Reputation: 1283
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]
Upvotes: 1
Views: 1231
Reputation: 1283
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]
Upvotes: 0
Reputation: 784998
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]
Upvotes: 1
Reputation: 145
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
Upvotes: 0