Search code examples
.htaccesshttp-redirectmod-rewriteurl-rewritingfriendly-url

Remove query param with URL Rewriting not working


I'm trying to rewrite the URL's with params contained looks like: https://mywebsite/FOF/news/page/page1.php?name=petter&country=usa

I think it's not very aesthetic as url and I would like it to look more like this:

https://mywebsite/spiderman

Actually the rewrite work and give me this result https://mywebsite/spiderman?name=petter&country=usa until https://mywebsite/spiderman

This is my redirected rules

##Enabling FollowSymlinks and disabling MultiViews options here.
Options +FollowSymlinks -MultiViews
##Setting rewrite base to / here.
RewriteBase /
RewriteEngine on
##Rewriting for page1 uri here.
RewriteRule ^page1$ page1.php    
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\s [NC]
RewriteRule ^ /customPage? [R=301,L]

##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customPage/?$ FOF/news/page/page1.php [L,NC]

if someone can help me


Solution

  • With your shown samples, attempts; please try following htaccess Rules. Where customPage is the page which you want to redirect on browser(spiderman in your shown question). This is for specific page request as per your shown samples.

    Make sure to clear your browser cache before testing your URLs.

    ##Enabling FollowSymlinks and disabling MultiViews options here.
    Options +FollowSymlinks -MultiViews
    ##Setting rewrite base to / here.
    RewriteBase /
    RewriteEngine on
    ##Rewriting for page1 uri here.
    RewriteRule ^page1$ page1.php    
    ##External redirect rules here.
    RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\?name=(?:[^&]*)&country=(?:\S+)\s [NC]
    RewriteRule ^ /customPage? [R=301,L]
    
    ##Internal rewrite rules here...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^customPage/?$ FOF/news/page/page1.php?name=petter&country=usa  [L,NC,QSA]