0

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!

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .