Jump to content

How can I redirect to index page removing all url parameters using apache rewriterule if file not found?


colap

Recommended Posts

I tried this in .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule "^(.+)" "/"

It works when the url looks like "http://localhost/project/xyz" , it redirects to "http://localhost/project/". But the url can be "http://localhost/project/xyz?id=5&t=abc", then it redirects to index page but the parameter is still there in url "http://localhost/project/?id=5&t=abc" , how can I remove all those parameters after redirecting to index page?

 

Link to comment
Share on other sites

Modifying the Query String

 

By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.

Link to comment
Share on other sites

Silently redirecting the user when the URL is erroneous is usually a very bad idea and can cause a lot of confusion. Errors should in fact be reported with a proper status code, so that the user can fix them or at least knows that there's a problem. There's a reason why the 404 code exists.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.