Question

I have an URL as :

http://mydomain.com/site/?cmd=home

I want to change the above address to http://mydomain.com/home

i am using .htaccess file like this:

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /site?cmd=$1 [L]

I am not sure where is the problem?

Thanks in advance

Was it helpful?

Solution

The Rule works the other way around: you want to get from /site/?cmd=home to /home, but with your RewriteRule you are redirecting to /site?cmd= (Probably there is a mistake somewhere?)

If you want to redirect from /site/?cmd=home to /home, like the question states, use the following:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/site
RewriteCond %{QUERY_STRING} ^cmd=(.*)$ 
RewriteRule ^(.*)$ /%1/? [R=302,L]

OTHER TIPS

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{THE_REQUEST} /site\?cmd=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]

# internal forward from pretty URL to actual one
RewriteRule ^([^/.]+)/?$ /site?cmd=$1 [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top