简体   繁体   中英

How to remove parameter from URL

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/?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.

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/?\?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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM