1

I have an htaccess that redirects any url except urls in 3 specific folders to a php file which handles displaying the page:

Options +FollowSymLinks  
RewriteEngine On  
RewriteCond %{REQUEST_URI} !^/app [NC]
RewriteCond %{REQUEST_URI} !^/templates [NC]
RewriteCond %{REQUEST_URI} !^/downloads [NC]
RewriteCond %{THE_REQUEST} \ /+([^\ \?]*)
RewriteRule (.*)$ ./app/index.php?url=%1 [L,B]

The problem is, however, any query info in the url is lost. I was wondering if it would be possible to retain that.

for example:

mysite.com/test?page=1 would become /app/index.php?page=1&url=test

rather than (Which is what happens now):

mysite.com/test?page=1 becomes /app/index.php?url=test

1 Answer 1

1

You just need a QSA flag here:

Options +FollowSymLinks  
RewriteEngine On  
RewriteCond %{REQUEST_URI} !^/app [NC]
RewriteCond %{REQUEST_URI} !^/templates [NC]
RewriteCond %{REQUEST_URI} !^/downloads [NC]
RewriteCond %{THE_REQUEST} \ /+([^\ \?]*)
RewriteRule (.*)$ ./app/index.php?url=%1 [L,B,QSA]

QSA (Query String Append) flag preserves existing query parameters while adding a new one.

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

Comments

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.