Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
RewriteRule ^index.php/(.*)$ redirect.php?s=$1

Works with

But not with

Any way to get this to work?

RewriteRule ^/(.*)$ redirect.php?s=$1 did not do the trick.

share|improve this question
I'm fairly sure just removing the slash in the rewrite would solve the problem. Can't test sadly. – Sašo May 15 '12 at 13:57
@ErikA Unfortunately that question and it's answer do not help me. All info on there is based on the assumption that there is something between the base url and what to rewrite to. Eg: RewriteRule ^/blog/(.*)$ /newblog/$1 instead of RewriteRule ^/(.*)$ /newblog/$1 – natli May 16 '12 at 8:35
@Sašo Unfortunately, no. That rewrites the entire url and not just what comes after the slash. – natli May 16 '12 at 8:37
up vote 1 down vote accepted

You should probably clarify a little more thoroughly what behavior you're looking for, but this is probably close to it..

# Don't redirect for /index.php or /index.php/
RewriteRule ^index\.php/?$ - [L]
# Don't redirect for /redirect.php
RewriteRule ^redirect\.php.* - [L]
# Redirect everything with /index.php/something, keeping everything after index.php/
RewriteRule ^index\.php/(.+)$ redirect.php?s=$1 [L]
# This request didn't start with one of the PHP files, so just dump the whole thing into the query parameter
RewriteRule ^(.*)$ redirect.php?s=$1 [L]
share|improve this answer
I just want to rewrite to redirect.php?s=something. But as it stands I have to explicitly type out or it will not work. Unfortunately your suggestion did not change this behavior. To simplify: This works -> RewriteRule ^test/(.*)$ redirect.php?s=$1 will rewrite. And this does not work -> RewriteRule ^/(.*)$ redirect.php?s=$1 does not rewrite. It should.. because I took out "test" in both the rewrite rule and the URL. – natli May 16 '12 at 8:31
No, it should not work. You added a leading slash to your pattern, which is not part of the match string in a <Directory> or .htaccess context. Remove that slash (as you'll see I did in the rule I provided) and it will work. – Shane Madden May 16 '12 at 16:11
I tried it on a local installation of apache2 and it works fine here. Apparently the host I am using screws up the redirect if the $_GET value ends in .com. Works fine with .org etc. Highly strange... but the .htaccess is not to blame, so thank you ;) – natli May 17 '12 at 8:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.