Home > Net >  How to remove parameter from URL
How to remove parameter from URL

Time:01-02

I apologise if this question is asked before but I can't find the specific instance for my problem.

How to achieve this www.example.com/index.php?user=john to www.example.com/john

I am using this already to remove the .php extension but it doesn't fix the user parameter.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.] )$ $1.php [NC,L]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R]

ErrorDocument 404 /error.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/([A-Za-z0-9_] ) ?user=$1

I highly value any reply. Please help.

CodePudding user response:

With your shown attempts, please try following htaccess rules. Considering that you have to pass your arguments to index.php file in backend.

Also make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/index\.php\?user=(\S )\s [NC]
RewriteRule ^ /%1? [R=301,L]

##Internal rewrite rules here..
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?user=$1 [QSA,L]
  • Related