鉴于我当前的.htaccess文件,我将如何修改它来检查像'/ src / pub / '的其他URLpath, 并重写它为'/ '而不影响当前重写?
这是原始的.htaccess文件:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
这是我最近的尝试(这是行不通的):
RewriteEngine on RewriteRule ^/src/pub/(.*)$ /$1 [R] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
编辑:这里是我想要完成的一些例子:
新的附加规则:
From: http://www.mysite.com/src/pub/validfile.php To: http://www.mysite.com/validfile.php From: http://www.mysite.com/src/pub/user/detail/testuser To: http://www.mysite.com/user/detail/testuser
现有规则(已经工作):
From: http://www.mysite.com/user/detail/testuser To: http://www.mysite.com/index.php?route=user/detail/testuser
我猜测问题是URL被第一个规则重写,然后被第二个重写。
解决方案是将“最后”标志添加到第一条规则,如下所示:
RewriteRule ^/src/pub/(.*)$ /$1 [R,L]
在一个.htaccess文件中,用这个代替:
RewriteRule ^src/pub/(.*)$ /$1 [R]
前面的“/”在.htaccess中不匹配,只有在httpd.conf
( src – 页面底部)内,如果你希望处理更多的规则停止,那么添加L
标志:
RewriteRule ^src/pub/(.*)$ /$1 [L,R]
重写日志比较(.htaccess上下文):
// using ^/src/pub/(.*)$ - leading slash will not work in .htaccess context! (1) pass through /home/test/src // using ^src/pub/(.*)$ (2) rewrite 'src/pub/testme' -> '/testme' (2) explicitly forcing redirect with http://test/testme (1) escaping http://test/testme for redirect (1) redirect to http://test/testme [REDIRECT/302]