Forum Moderators: phranque
I am a novice to Apache and mod_rewrite.
I am just trying to rewrite a simple URL, as given below:
mysite.com/directory/directory.php?cat=10
to
mysite.com/directory/dir10.html
but its not working on server. What Im using is this code within .htaccess file:
RewriteEngine on
RewriteRule ^dir(.*)\.html$ /directory/directory.php?cat=$1 [L,NC]
Please suggest if there is any other settings or code I have to change or use, I dont know much about this .... I am using just what I got on net.
My site is hosted on linux server (site5.com hosting) and they have confirmed that their server supports mod_rewrite.
Please help...!
Thanks in advance
Welcome to WebmasterWorld!
It's likely that you're going about this backwards: Apache mod_rewrite changes incoming URL requests, so that the 'new' URL can be used to access the 'old' content. It does not act as an output filter, changing the links that are output to the client when someone views your pages.
So, the first step is to change the links on your pages, and the second step is to add mod_rewrite code, so that those links can be used to access the correct content on your site. In reality, you'll want to put the rules in place first, but you still have to change the links on your pages. For php-driven sites, this is usually done by changing the URLs in the database associated with each page, or by using the php preg_replace function to change them on-the-fly.
After you get that working, you may want to add additional code to redirect the old URLs to the new URLs. But this can be tricky, and I'd advise you to defer that until you get the above functions implemented and are more comfortable with how it all works.
A good place to start is: here [webmasterworld.com]
There are also several very useful links in our forum charter (link at upper left of this page).
Jim