1

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=$1

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)

  • Your URL has the "simran" directory in it but the rewrite rule does not. Have you tried putting that into your rewrite rule? – Stephen Ostermiller Feb 28 '15 at 11:48
1

Easiest way is to Change:

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

to:

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

or for more flexibility you can use:

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

That should make these URL's work

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

I changed $1 to $2 because $1 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.