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 its 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.

Accepted Answer

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

Written by MNeimeier
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki