简体   繁体   中英

Remove query string and make clean url using htaccess

I have url's like following with query string. I want to remove query string from url and want to make clean url.

www.demo.com/following.php?user=hardik
www.demo.com/fans.php?user=john

This url's should be like

www.demo.com/hardik/following
www.demo.com/john/fans

OR should be like

www.demo.com/following/hardik
www.demo.com/fans/john

Is this possible with htaccess? I tried to find a loot in google but still no luck. Need help.

Update:

I need something like this

www.demo.com/user/hardik/following/
www.demo.com/user/john/fans/

I tried like this

RewriteRule ^user/([^?]*) following.php?user=$2/ [L,QSA]

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

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/(\w+)/(\w+)/?$ $2.php?user=$1 [L,QSA,NC]

Try with this for a url like www.demo.com/following/hardik

Options +FollowSymLinks

RewriteEngine on

RewriteRule ^([a-zA-Z_-]+)/([a-zA-Z_-]+)/?$ $1.php?user=$2

Finally this is working for me for my last requirement. May be help someone else.

RewriteEngine On
RewriteBase /

RewriteRule ^user/([^*]+)/following/$ following.php?user=$1 [L,QSA]
RewriteRule ^user/([^*]+)/fans/$ fans.php?user=$1 [L,QSA]

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