0

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

3 Comments

+1, its within a directory (shared hosting on plesk without virtual host permissions)
@Sam Can you please post the directory section (and the alias if you use one). It makes it much simpler to analyse.
I rephrased my question. Does that help? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.