Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've googled this but can't seem to figure out.

I'm looking to simply redirect any path requested to a GET parameter in index.php:

RewriteEngine on
RewriteBase  /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/.+\.(js|css|png|jpg|gif|ico)$

RewriteRule ^(.*)$ http://localhost/site/index.php?request_url=http://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]

Now, redirect works but it's painfully slow, and gets executed twice.

Do I have to add another condition that checks whether request_url is already there? If so, how do I write that? Can't seem to figure out.

Right now it's not exactly a redirect loop, just really slow.

Any help appreciated.

Thanks a 1000!

share|improve this question

1 Answer 1

Does it help if you change your rewrite rule to:

RewriteRule .* /site/index.php?request_url=http://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]

The main difference is to remove the leading http://localhost from the target. That might help because if %{HTTP_HOST} is different from localhost, then Apache will issue an external redirect: see the paragraph titled "Absolute URL" in the RewriteRule documentation. That will take twice as long, as you say.

I also simplified the match pattern to just .*, but this is just a minor cleanup. There's no need for the constraining matches ^...$, and no need to capture with (...) either since you're not using the captured value in the rule target.

share|improve this answer

Your Answer

 
discard

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.