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 / /tmp/

<Directory /tmp/>
  Options FollowSymLinks
  RewriteEngine On
  RewriteRule ^index.htm /en/somepage [R=301]

If I use "" it gets rewritten to ""

(3) [perdir /tmp/] strip per-dir prefix: /tmp/ -> index.htm
(3) [perdir /tmp/] applying pattern '^index.htm' to uri 'index.htm'
(2) [perdir /tmp/] rewrite 'index.htm' -> '/en/somepage'
(2) [perdir /tmp/] explicitly forcing redirect with
(1) [perdir /tmp/] escaping for redirect
(1) [perdir /tmp/] redirect to [REDIRECT/301]

If I use "" it doesnt get rewritten

(3) [perdir /tmp/] add path info postfix: /tmp/ -> /tmp/
(3) [perdir /tmp/] strip per-dir prefix: /tmp/ -> someotherfolder/index.htm
(3) [perdir /tmp/] applying pattern '^index.htm' to uri 'someotherfolder/index.htm'
(1) [perdir /tmp/] pass through /tmp/


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 community.
It is licensed under cc-wiki