Mobile app version of vmapp.org
Login or Join
Cody1181609

: What is the htaccess code for a clean URL for a user profile page? I have tried code given on under topic clean URLs using .htaccess, but it is nor working on my website. Actually I am

@Cody1181609

Posted in: #CleanUrls #Htaccess #Url

I have tried code given on under topic clean URLs using .htaccess, but it is nor working on my website.

Actually I am getting static content, but not getting parameters (dynamic content.) My .htaccess code is

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^user/([^/]+) /user.php?u=


My PHP file (user.php) is:

<?php
echo "ABC";
echo $_GET['u'];

?>


My URL is:

example.com/simran/user/jack


(getting static contents , but not parameters)

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Cody1181609

1 Comments

Sorted by latest first Latest Oldest Best

 

@Deb1703797

Easiest way is to Change:

RewriteRule ^user/([^/]+) /user.php?u=


to:

RewriteRule ^simran/user/([^/]+) /user.php?u= [L]


or for more flexibility you can use:

RewriteRule ^(.*)/user/([^/]+) /user.php?u= [L]


That should make these URL's work

example.com/any1user/user/jack
example.com/simran/user/jack
example.com/user/jack


I changed to because now points to contents before /user and you're interested in contents after /user. The .* means anything including nothing and punctuation.

In all cases, I always recommend suffixing a rule with an L in square brackets because it means don't process any further rules in the list after the rule is processed.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme