In my website there is a link to registered tutors. That link is something like this
http://www.myweb.com/profiles/tutors/index.php?tutorCode=1285&tutorName=Robert%20Sakoo&city=Sidny
So I need to rewrite this link something like this:
www.myweb.com/1285/Rober Sakoo
Can anybody tell me is it possible to rewrite above original URL to my expected URL?
What are SEO friendly URLs? SEO friendly URLs are URLs that are designed to meet the needs of users and searchers. Specifically, URLs optimized for SEO tend to be short and keyword-rich.
You seem to be confused with how URLs and rewriting works. The notion that "I need to rewrite this2 to this1 " means:
Note that the important concept in all of this is that the browser requests for the "this2" link, and the server internally rewrites the request to "this1". But this is probably not what you want at all, because then you'd be taking the ugly URLs and rewriting them to the nice looking URLs, sort of missing the point of friendly looking URLs.
Too often, especially around here, people ask for stuff like "I want to change this url to this url", or asking for rewrite when there's a 2 step redirect process. This is the 2nd step (which you are not asking for at all) which takes this1 and redirects the browser to this2 so that the url address bar changes to this2:
So this whole round-about convolution is just so when the browser tries to go to this1, it gets redirected to this2 but still actually gets served the content from this1.
So I assume this must be what you want. Try putting this in your htaccess file:
RewriteEngine On
# check if the actual request if for "this1"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profiles/tutors/index.php\?tutorCode=([0-9]+)&tutorName=([^&]+)&?([^\ ]+)
# redirect to "this2"
RewriteRule ^profiles/tutors/index\.php /%1/%2/?%3 [R=301,L,NE]
# now rewrite "this2" back to "this1"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)/$ /profiles/tutors/index.php?tutorCode=$1&tutorName=$2 [L,QSA]
Note that the city
parameter is never being encoded in the friendly URL, so it's left as part of the query string. You could change this so that the friendly URL looks like: /id/name/city/
instead of just /id/name/
, that modification should be trivial.
That would be somewhere near:
RewriteEngine on
RewriteRule ^([0-9]+)/(.+)$ /profiles/tutors/index.php?tutorCode=$1&tutorName=$2 [NC,QSA]
Since you're not specifying what to do about it, i didn't take your city
parameter into account, thus added QSA
(Query String Append) to the rule so parameters in GET are still passed on to the script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With