How to Redirect Only the Main Root/index.php and not Root/Folder/index.php via RewriteRule?
Dear folks, Currently a rewrite should redirect
/index.php
to /en/home
And for that this works fine via the following rule:
RewriteRule ^index.php /en/home [R=301]
However, when /someotherfolder/index.php
is called, even then it redirects to /en/home
while it should not! How can I hardcode it to ONLY rewrite, on the condition that it开发者_如何学Cs the root-index.php file, and not just any index.php file sitting in other deeper folders?
Thanks very much for your suggestions! Much appreciated.
here is a working sample, hope this helps.
RewriteLog "/var/log/httpd/rewrite_log"
RewriteLogLevel 3
Alias /dummy.org /tmp/dummy.org
<Directory /tmp/dummy.org>
Options FollowSymLinks
RewriteEngine On
RewriteRule ^index.htm /en/somepage [R=301]
</Directory>
If I use "http://127.0.0.1/dummy.org/index.htm" it gets rewritten to "http://127.0.0.1/en/somepage"
(3) [perdir /tmp/dummy.org/] strip per-dir prefix: /tmp/dummy.org/index.htm -> index.htm
(3) [perdir /tmp/dummy.org/] applying pattern '^index.htm' to uri 'index.htm'
(2) [perdir /tmp/dummy.org/] rewrite 'index.htm' -> '/en/somepage'
(2) [perdir /tmp/dummy.org/] explicitly forcing redirect with http://127.0.0.1/en/somepage
(1) [perdir /tmp/dummy.org/] escaping http://127.0.0.1/en/somepage for redirect
(1) [perdir /tmp/dummy.org/] redirect to http://127.0.0.1/en/somepage [REDIRECT/301]
If I use "http://127.0.0.1/dummy.org/someotherfolder/index.htm" it doesnt get rewritten
(3) [perdir /tmp/dummy.org/] add path info postfix: /tmp/dummy.org/someotherfolder -> /tmp/dummy.org/someotherfolder/index.htm
(3) [perdir /tmp/dummy.org/] strip per-dir prefix: /tmp/dummy.org/someotherfolder/index.htm -> someotherfolder/index.htm
(3) [perdir /tmp/dummy.org/] applying pattern '^index.htm' to uri 'someotherfolder/index.htm'
(1) [perdir /tmp/dummy.org/] pass through /tmp/dummy.org/someotherfolder
-Martin
the best to debug RewriteRule, is to turn on logging of the rewrite process.
<VirtualHost x.x.x.x>
...
RewriteEngine On
RewriteLog "/var/log/httpd/rewrite_log"
RewriteLogLevel 3
RewriteRule .....................
...
</VirtualHost>
One question, is the RewriteRule within a VirtualHost section or within a Directory section ?
-Martin
精彩评论