Dominee
Dominee

Reputation: 11

?action= delete from url with RewriteRule Htaccess

I am trying to solve the following problem:

Given a url such as

domain.com/?action=param

I want to delete the ?action= from the url.

I thought to solve it with the following rewrite rule

  RewriteRule ^$ /?action=$1

or

  RewriteRule ^(.*) /?action=$1

However, this did not work. Any idea?

Upvotes: 1

Views: 111

Answers (3)

Panama Jack
Panama Jack

Reputation: 24468

I think somewhere in the problem description, your problem got lost. If I get what you're trying to do, as you said only wanted to remove ?action= which would leave just the param so you can use a URL like this

http://domain.com/param

If that is what you are looking for. Try this rule.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?action=$1 [QSA,L]

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143906

Try:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^action=
RewriteRule ^ %{REQUEST_URI}? [L,R=301]

Upvotes: 0

Drewness
Drewness

Reputation: 5072

Will remove all query string parameters:

RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*) /$1? [R=301, L]

Upvotes: 0

Related Questions