Я пытаюсь переписать подкаталог из структуры URL-адреса, но также работают другие URL-адреса внутри этой структуры каталогов. У меня есть такой сценарий:Используйте .htaccess, чтобы переписать подкаталог в корневой каталог, но сохранить доступ к другим подкаталогам
// This should load the content of mysite.com/foo/15 but not redirect
mysite.com/foo/
// Subdirectories within /15 should also work
mysite.com/foo/bar // the actual location of this is mysite.com/foo/15/bar
// Other URLs within this directory structure should also work, such as
mysite.com/foo/12
mysite.com/foo/13
mysite.com/foo/14
// Lastly, we have redirects from 2012 -> 12, 2013 -> 13 such that
mysite.com/foo/2012 becomes mysite.com/foo/12
mysite.com/foo/2013 becomes mysite.com/foo/13
... and so on
Вот где я нахожусь. Я не могу получить правильную комбинацию правил htaccess для достижения того, чего хочу.
RewriteEngine On
RewriteBase /foo/
// This makes mysite.com/foo/ load the content of mysite.com/foo/15 without redirecting, but makes mysite.com/foo/14 404
RewriteRule ^((?!15/).*)$ 15/$1 [NC,L]
// This works pretty well, except the rules below don't redirect
RewriteRule ^$ 15/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 15/$1
// Rewrite old years to the two digit form
RewriteRule ^2010/(.*)$ 10/$1 [R=301]
RewriteRule ^2011/(.*)$ 11/$1 [R=301]
RewriteRule ^2012/(.*)$ 12/$1 [R=301]
RewriteRule ^2013/(.*)$ 13/$1 [R=301]
RewriteRule ^2014/(.*)$ 14/$1 [R=301]
RewriteRule ^2015/(.*)$ 15/$1 [R=301]
Что мне не хватает? Какая комбинация правил поможет мне достичь того, что я ищу?
Отлично работает, спасибо! 'RewriteRule^20 (1 [0-5])/(. *) $ $ 1/$ 2 [R = 301, L]' был довольно умным. – Dan