Forum Moderators: phranque
i want them to redirect to
mydomain.com/pages/[urlid]/somepage.html
I have completely deleted my old-pages and I just want to make sure that the google cache has the new url now and visitors do not get redirect to an error page.
that [urlid] in my url are numbers such as 1, 2, 3 and I have around 300 urls with different [urlid]s
What do I do? Please help me out here. Thanks
The code you need will be fairly simple because you are re-using the same number ID.
Use a
RewriteRule with [R=301,L] and make sure that the target URL specifies the full domain name too. Post your best effort code here as a basis for discussion.
RewriteRule ^(.*)$ %{ENV:askapache}://www.thedomain.com%{REQUEST_URI} [L,R=301]
I have no idea how to convert the above to make it work according to how i need. :(
Which part of it do i edit?
Should I do something like
RewriteRule ^(.*)$ %{ENV:askapache}://www.thedomain.com/old-page/[urlid]/ www.thedomain.com/new-page/[urlid]/[L,R=301]
If "somepage" is always the same -- literally "somepage.html", then the following will redirect, copying the "urlid" from the old to the new URL as back-reference $1 :
Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^old-pages/([^/]+)/somepage\.html$ http://www.example.com/pages/$1/somepage.html [R=301,L]
If "somepage.html" can take other values and you want to redirect them as well, then you'll need to be very, very specific and describe those values. (mod_rewrite is all about "very, very specific")
You may or may not need the first line of code (the Options directive). If you don't need it, your host may not allow you to use it, and it will cause a 500-Server error. If you do need it and don't include it, then you'll also get a 500-Server error. Try with and without that line.
See the resources cited in our Forum Charter, and the threads in the Apache Server section of the WebmasterWorld Library for more background information.
Jim
RewriteRule ^old-pages/([^/]+)/([^.]+)\.html$ http://www.example.com/pages/$1/$2.html [R=301,L]
Note also that "?" will never appear in the URL-path "seen" by RewriteRule; The query string, if any, must be handled separately using a RewriteCond. If you do not append any query string data to the substitution URL in your RewriteRule, then by default, any query string appended to the requested URL-path will be passed through the rule unchanged.
Jim
[edited by: jdMorgan at 5:32 pm (utc) on Dec. 15, 2008]