colap Posted April 2, 2017 Share Posted April 2, 2017 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? Quote Link to comment https://forums.phpfreaks.com/topic/303600-how-can-i-redirect-to-index-page-removing-all-url-parameters-using-apache-rewriterule-if-file-not-found/ Share on other sites More sharing options...
kicken Posted April 2, 2017 Share Posted April 2, 2017 (edited) 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. Edited April 2, 2017 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/303600-how-can-i-redirect-to-index-page-removing-all-url-parameters-using-apache-rewriterule-if-file-not-found/#findComment-1544935 Share on other sites More sharing options...
Jacques1 Posted April 2, 2017 Share Posted April 2, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303600-how-can-i-redirect-to-index-page-removing-all-url-parameters-using-apache-rewriterule-if-file-not-found/#findComment-1544942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.