Reputation: 444
I am trying to use Apache mod_rewrite to have SEO URLS I have the following:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1
RewriteRule ^([^/]*)\.php$ /index.php?a=$1 [L]
RewriteRule ^([^/]*)/([^/]*)\.php$ /index.php?a=$1&id=$2 [L]
The first part which is redirect to www and https works fine but I need to achieve the following URL rewrites which is not working:
https://www.domain.com/index.php?a=explore
to https://www.domain.com/explore/
https://www.domain.com/index.php?a=page&b=about
to https://www.domain.com/about/
https://www.domain.com/index.php?a=track&id=9
to https://www.domain.com/track/idno
https://www.domain.com/index.php?a=explore&filter=newtag
to https://www.domain.com/explore/newtag/
Upvotes: 0
Views: 641
Reputation: 80657
The following rule should work:
RewriteCond %{THE_REQUEST} ^GET\ /index\.php?a=(explore)(?:&filter=([^\s&]+))? [NC]
RewriteRule ^index\.php$ /%1/%2? [R=301,L,NC]
RewriteCond %{THE_REQUEST} ^GET\ /index\.php?a=(track)&id=(\d+) [NC]
RewriteRule ^index\.php$ /%1/%2/? [R=301,L,NC]
RewriteCond %{THE_REQUEST} ^GET\ /index\.php?a=page&b=about [NC]
RewriteRule ^index\.php$ /about/? [R=301,L,NC]
RewriteRule ^(explore)/(.*)/?$ /index.php?a=$1&filter=$2 [L]
RewriteRule ^(track)/(\d+)/?$ /index.php?a=$1&id=$2 [L]
RewriteRule ^(about)/?$ /index.php?a=page&b=$1 [L]
Upvotes: 2