Reputation: 31337
I have the following .htaccess at present.
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/abc/php.ini
</IfModule>
RewriteEngine on
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
AuthType Basic
AuthName "Está dominado!!"
AuthUserFile "/home/abc/.htpasswds/public_html/passwd"
require valid-user
Now the thing is, I would like to, if any query string is found after a / remove that query string.
So: If we have:
http://www.abc.com/?somethinghere234
It should redirect to:
http://www.abc.com/
If we have:
htpp://www.abc.com/something/?id212
Redirect to:
htpp://www.abc.com/something/
UPDATE: I've tried this:
TRY A)
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* /index.php/ [L,QSA]
Hopping that ^(.*)$ will allow anything on the query string...
I've also tried this:
TRY B)
RewriteEngine on RewriteCond $1 !^(index.php|media|css|js|images|robots.txt) RewriteCond %{QUERY_STRING} ^(.)$ RewriteRule ^(.)$ http://abc.com/ [L]
This returns a 500 internal server error.
TRY C)
RewriteEngine on
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
#RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://abc.com/ [R=302,L]
I confess I'm kind of lost on this .htaccess sintax.
TRY D)
RewriteEngine on
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
RewriteCond %{REQUEST_URI} !^/
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://abc.com/ [R=302,L]
Please advice, MEM
Upvotes: 2
Views: 18487
Reputation: 17205
RewriteCond %{REQUEST_URI} ^(.*/)([^/]+)$
RewriteRule . %1 [R=301,L]
Upvotes: 0
Reputation: 1064
The following should work:
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^ /index.php/? [L]
From the Apache documentation:
When you want to erase an existing query string, end the substitution string with just a question mark
EDIT (again): As external redirect (you may not even need the second RewriteCond if you don't have any query string at all in your application):
This will tell the client to request the same URI without query string.
RewriteEngine on
# redirect to same URI, but without query string
RewriteCond %{QUERY_STRING} .
RewriteRule ^ %{REQUEST_URI}? [R=301]
# CodeIgniter "magic"
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Upvotes: 5
Reputation: 19169
I wasn't sure from your description exactly what you were after, so you should keep or remove the second RewriteCond depending on your specific needs.
RewriteEngine On
# Remove the query string with a redirect
RewriteCond %{QUERY_SRING} !=""
# But only if the path ended with a /
# (remove this to redirect anything with a query string)
RewriteCond %{REQUEST_URI} /$
RewriteRule .* /$0? [R=301,L]
# Then perform your internal rewrite
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Upvotes: 2
Reputation: 20602
Possibly because you have QSA added on there - it means Query String Append.
Upvotes: 1