0

In my website there are lot of ugly URLs and now I need to rewrite them to nice user friendly URLs.

These are some of ugly URLs from my website :

http://www.mydomain.com/profiles/tutors/index.php?code=1285&name=Ricky+Pointing
http://www.mydomain.com/profiles/centers/index.php?code=2285&name=City+&+Gills
http://www.mydomain.com/about.php
http://www.mydomain.com/contact.php.... and much more

So I am looking for nice user friendly solution to above ugly URLs, something like this :

http://www.mydomain.com/tutors/Ricky_Pointing.html
http://www.mydomain.com/centers/City_&_Gills.html
http://www.mydomain.com/about.html
http://www.mydomain.com/contact.html

I tried it something similar this in my .htaccess file..

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profiles/tutors/index.php\?code=([0-9]+)&name=([^&]+)&?([^\ ]+)
RewriteRule ^profiles/tutors/index\.php /%1/%2/?%3 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)/$ /profiles/tutors/index.php?code=$1&name=$2 [L,QSA]

But still no luck. Can anybody help me to do this? Thank you.

TNK
  • 4,263
  • 15
  • 58
  • 81
  • You always can use url shortners. You can find more info from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener – AliBZ May 20 '13 at 04:18
  • I know, I didn't mean to convert it to something like http://www.mydomain.com/dgGc32G. I meant something like http://www.mydomain.com/Ricky_Pointing. You are right, it could be done by adding another column to the database and store the shortened url. It doesn't need an actual url shortner. – AliBZ May 20 '13 at 04:22

1 Answers1

0

I think you might be overcomplicating it with RewriteConds and such. You'll probably have rules like this:

RewriteRule ^about\.html$ about.php [L]
RewriteRule ^contact\.html$ contact.php [L]
RewriteRule ^tutors/(.*)\.html$ /profiles/tutors/index.php?name=%1 [L]
RewriteRule ^centers/(.*)\.html$ /profiles/centers/index.php?name=%1 [L]

You'll then have to modify your PHP scripts to look up the appropriate thing with that name without relying on having the code present. It'll also have to deal with the presence of underscores as existed in the original URL.

icktoofay
  • 126,289
  • 21
  • 250
  • 231