Forum Moderators: phranque
Ok, I am running my own sports site that uses a lot of query strings in the URLs and I want to rewrite them to make them more seach engine friendly. I want to change a URL from say:
[domain.com...]
to
[domain.com...]
Now, here's my problem. I used the mod_rewrite to write the new URL and it works, as long as I type the [domain.com...] into the browser myself. However if I go through my site and click on the link to see the interview, I get [domain.com...] in my address bar instead of the rewritten URL.
Should I not see the rewritten URL instead of the original one?
Here is what is in my .htaccess file.
RewriteEngine on
RewriteRule interview(.*)\.html$ /viewinterview.php?id=$1 [L]
Any help would be appreciated, thanks.
Welcome to WebmasterWorld!
Sounds like you're only half-done...
Mod_rewrite can translate the requested url "http://www.domain.com/interview105.html" to "http://www.domain.com/viewinterview.php?id=105", but it cannot change the links on the pages output by your script.
In order to make your site search-engine friendly, your script itself needs to output the friendly URLs in your on-page links. Then, once one of those friendly links is clicked, you use mod_rewrite on the server to change it back to the form needed to call your script instead of accessing the non-existent html page.
So, you've got the second part, now you need to add the script modifications to output the friendly URLs in your on-page links. (Note that I'm being general here; I don't know if your script builds the whole page dynamically, or if it just gets content from fixed files containing the interviews. Either way, the URLs in the links that appear on your pages need to be changed to be in the "http://www.domain.com/interview105.html" format.)
Message two of this recent thread [webmasterworld.com] also describes the actions of the mod_rewrite code and your script.
Also, you can speed up your rule by making the pattern less ambiguous:
RewriteRule ^interview([^.]+)\.html$ /viewinterview.php?id=$1 [L]
Jim