Just getting into working with mod_rewrite and this thread has been incredibly helpful so far. I'm having some trouble with my own (first attempt) url rewriting. I've got some bigger plans to make but I figured I'd start simple, especially since the change I'm trying to make is relevant. I've got a music review site and I've recently changed the link scheme from review.php?reviewID=* to review.php?type=album&reviewID=* where the IDs are numbers. This change was to accomodate different types of reviews and after reading about mod_rewrite I plan to make these urls less ugly and more memorable. But as it stands now I have a record label that I've done reviews for who has linked to the reviews on their own site. The problem is theyve used the old link scheme, and I'm worried about search engines still crawling the old links. To save them the cash on an out of schedule update I've rigged it so that review.php?reviewID will still point to album reviews, and place that amidst the new link scheme/php layout. However I'd like to cut this off altogether and use the new link scheme, without causing them to change their links. The rule I've set is: RewriteRule ^review\.php?reviewID=([0-9]+)$ review.php?type=album&reviewID=$1 [R=301,L] I've toyed around with the [R=301,L] portion a bit as well. I'm running into 2 problems: The old links are still showing up in the address bar and I'm worried that search engines will crawl them as such. This for whatever reason has cut off the logo at the top of the page, I think that might just be a relative scripting thing and am checking on that now. If someone could take a look at that and see where I've gone wrong it'd be really helpful. Thanks
RewriteRule ^review\.php?reviewID=([0-9]+)$ review.php?type=album&reviewID=$1 [R=301,L] looks like you're redirecting to a more dynamic URL. If you change the URLs, you want static URLs, and you can't both change a URL, and do a 301 redirect at the same time. RewriteRule ^review/([0-9]+)/$ review.php?type=album&reviewID=$1 [L] Enter the full URL in the image code for the logo.
i guess i should just bypass the middleman i was going through for redirecting to the new url scheme and go static all around. thanks for the help! i guess the [L] is what sticks the friendlier url in the address bar another question: if i rewrite urls from dynamic to static with faux-subdirectories like from review.php?id=2 to reviews/2/, and someone enters reviews/4/ instead of clicking on review.php?id=4, would it parse that page correctly as if it were review.php?id=4. and is it good practice to switch all links coded into the site to the new simpler format or can i continue using url parameters i guess im just confused as to what rewriting urls actually does for the end user or an SE bot, i'll browse around the forum some more edit: alright i guess i was ass-backwards. understanding it better and i'll give it another go. thanks nintendo for the leg-up
finally got the hang of it and am currently editing my php pages to point to the new links. wanted to say thanks again for the effort helping everyone out (this goes to everyone else as well). when i first got wind of mod_rewrite a few weeks back and took a look at what was involved it looked far too daunting. feelin a lot more confident and optimistic about it now that i have some kind of idea what im doing.
Hi I have a question about Mod_rewrite. How would I be able to 301 redirect all non php pages to the home page. For example if I had a URL http://www.example.com/directory/filename.html or http://www.example.com/directory/subdirecory/f76543.aspx these would then 301 redirect to http://www.example.com/ Reason for doing this is we have a bunch of pages googles index/cache that hold some pagerank and we were hoping to transfer some of that pr to the homepage... Thanks
Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^directory/subdirecory/([^.]+)\.aspx$ http://www.domain.com/$1/ [R=301,L] RewriteRule ^directory/filename.html$ http://www.domain.com/ [R=301,L]
Big thanks for this thread. Have been searching the net for ages for some decent info on mod rewrites. Finally found it!! Now t0 give it a try ..
This is good info but I guess one should have done this when starting the webpage. Not a couple of months old one like mine. I made a redirect from non-www to the www version and lost pretty much all traffic from google. I thought it would not lose any traffic because all my incoming links is to the www address. What's the reason for this to happen? It only affected google searchengine. On MSN and other searchengines I'm at the top as I was on google before the 301.
hai Nintendo... thanx for the great tutorial....after reading this i managed to get the www and non-www issue sorted out... but when i tried to redirect index.html to www.domain.com/ It did not work out. the firefox browser says that the redirection request could not be completed. this is the code i have in my htaccess modelled on what you have given above... my idea behind this code segment is to redirect domain.com, domain.com/index.html and www.domain.com/index.html to www.domain.com in the above code, the first part works i.e. non-www to www code...but the second segment doesn't . what am i doing wrong here? thanx for your guidance.. cheers deepak.c
i dont understand this .....suppose like you said both are using the same file, then how come: www.domain.com is having a PR of 5 and cached on 7 april 06 while www.domain.com/index.html is not having any pr and is also cached on same date.
then what shall i do now... basically now i have two sites with similar content... www.domain.com and www.domain.com/index.html ur suggestions...
that is ok...inside the website i can do that. but what will happen if google comes to find about the two website types...i.e. index.html and / regards, deepak.c
Only way for Google to find it is through a link. I got a few vBulletin boards that have two URLs for the index and I have yet to ever get banned for duplicate content from one duplicate URL.
so your suggestion is to ignore completely the index.html and conc. only / so that google automatically ignores the index file..... ok... i will start working on that... regards, deepak.c
Nintendo, thanks for the helpful thread. I have read all the way through it and testing every combination to get the rewrites to work without success. I need: http://www.my site.com/view_offer.php?id=71 to go to: http://my site.com/viewoffer-71.html Similarly: http://www.my site.com/selloffers.php to go to: http://www.my site.com/selloffers.htm My .htaccess currently shows (not including my failed attempts at the above): Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} !^www\..* [NC] RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301] RedirectMatch permanent ^/gen_confirm.php$ http://www.my site.com Anyhelp would be greatly appreciated, thanks!