1

Iam having a url structure http://mywebsite.com/trainer-profile.php?usr=DarwinDiaz&id=MTE4 Added the htaccess code and removed .php extension from the link.

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^forums/ - [L,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

Now my URL Structure is http://mywebsite.com/trainer-profile?usr=DarwinDiaz&id=MTE4 . I want to convert this url to http://mywebsite.com/trainer-profile/DarwinDiaz. Iam new to htaccess. Tried different htaccess codes but did't work Thanks in advance

5
  • @anubhava once u have helped me in solving clean url using htacces.. But still now I dont know how to pass muliple variables in url. link to my question Need little help in multiple parameters in url..
    – Rakesh
    Dec 1, 2014 at 10:20
  • yes id=555, 555 is converted to its base64_encode()
    – syam deth
    Dec 1, 2014 at 10:20
  • @RakeshRajan: Please post a new question, better not to alter old questions.
    – anubhava
    Dec 1, 2014 at 10:24
  • Can u please edit the htaccess code and is it possible to change mywebsite.com/trainer-profile/DarwinDiaz/MTE4 @anubhava
    – syam deth
    Dec 1, 2014 at 10:28
  • Iam new to htaccess. Can u please edit my htaccess code to meet my requirement
    – syam deth
    Dec 1, 2014 at 10:31

2 Answers 2

1

You can use:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^forums/ - [L,NC]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301,NE]

RewriteCond %{THE_REQUEST} \s/+(trainer-profile)\.php\?usr=([^\s&]+)&id=([^\s&]+) [NC]
RewriteRule ^ %1/%2/%3? [R=302,L,NE]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php\s [NC]
RewriteRule ^ %1 [R,L]

RewriteRule ^(trainer-profile)/(\w+)/(\w+)/?$ $1.php?use=$2&id=$3 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
4
  • Sorry.. its not changing my url structure. Copied the above code and updated htaccess.
    – syam deth
    Dec 1, 2014 at 10:38
  • In the browser enter URL as: http://mywebsite.com/trainer-profile.php?usr=DarwinDiaz&id=MTE4 and see what it becomes.
    – anubhava
    Dec 1, 2014 at 10:40
  • Yes its working. Changed the url format but page css not working
    – syam deth
    Dec 1, 2014 at 10:43
  • css/js is different problem due to your use of relative paths. Use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /. You can try adding this in your page's HTML header: <base href="/" /> so that every relative URL is resolved from that URL and not the current URL.
    – anubhava
    Dec 1, 2014 at 10:43
1

I'd suggest keeping it simple, like this:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /trainer-profile.php?usr=$1&id=$2 [L]

It puts out address like http://mywebsite.com/DarwinDiaz/MTE4, in which you have both usr and id, but without unnecessary elements.

2
  • Strange. Are you sure you're using the scheme I've posted? Dec 1, 2014 at 10:37
  • Copied and updated the htaccess code with your code.
    – syam deth
    Dec 1, 2014 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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