Forum Moderators: phranque
My case:
I have a simple web structure:
www.mydomain.com/page1.htm
www.mydomain.com/page2.htm
www.mydomain.com/page3.htm
www.mydomain.com/pageX.asp
www.mydomain.com/pageZ.asp
And Im switching over a more complex PHP:
www.mydomain.com/folder/page1.php?pID=1
www.mydomain.com/folder/page7.php?pID=4
www.mydomain.com/folder/page2.php?pID=3
www.mydomain.com/folder/page10.php?pID=15
www.mydomain.com/folder/page1.php?pID=4
with several more pages with the same above structure and:
www.mydomain.com/folder/page.php?pID=5&uID=14
My intentions:
1. Want to redirect the basic old structure to the equivalent ones (with constant url) on the new php web. Reason: to keep my PageRank and don't want to worry about the backlinks.
2. Want to rewrite my urls to be more Search Engines/Robots/Spiders friendly...maybe more human friendly also ;).
3. Also I want to have:
a) just few landing pages with a more descriptive url,
b) the rest with a general url, for example several "www.mydomain.com/folder/page.php?pID=5&uID=14" with more random uID values.
My work:
redirect 301 /page1.htm folder/page1.php?pID=1
redirect 301 /page2.htm folder/page7.php?pID=4
redirect 301 whatever/ folder/page1.php?pID=1
redirect 301 folder/([a-z]+)([0-9]+)\.php\?pID\=([0-9]+) www.mydomain.com
redirect 301 folder/([a-z]+)([0-9]+)\.php\?pID\=([0-9]+)\&uID\=([0-9]+) www.mydomain.com
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^folder/page1.php?pID=1$ whatever/ [R=301,L]
RewriteRule ^folder/page7.php?pID=4$ whoever/ [R=301,L]
RewriteRule ^folder/([a-z]+)([0-9]+)\.php\?pID\=([0-9]+)$ example/ [R=301,L]
RewriteRule ^folder/([a-z]+)([0-9]+)\.php\?pID\=([0-9]+)\&uID\=([0-9]+)$ example/ [R=301,L]
...The first two redirects are kinda obvious, the next two redirects are something I thought I should have in case someone bookmark the RewriteRule urls that result from the next section of code.
So if I understand it, the first RewriteRule should write the url "www.mydomain.com/whatever/", and same thing works for the second one. The third one should work for the rest of pages not considered by the previous 2 rules, and again same thing goes for the last one.
I can't test it right now, because my hosting still needs to set up the new Linux server, but I want to be ready.
Thank you in advance.
# Rewrite Old URL-paths to new files or scripts
RewriteRule ^page1\.htm$ /folder/page1.php?pID=1 [L]
# Redirect client requests for new URL-paths back to old URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /folder/page1\.php\?pID=1\ HTTP/
RewriteRule ^folder\.page1\.php$ http://www.example.com/page1.html [R=301,L]
Jim
AddType application/x-httpd-php .asp
This will help you not lose your place in the search engines and it will add a level of security. People won't try to hack your code.
If you have to switch I would not go with the ugly URL's. Don't use question marks, periods, ampersands, or equal signs.
Read this post [webmasterworld.com].
Thanks, even thought I believe that is more information that I can handle. Anyway, I will try to learn it and test it before asking again.
@ ogletree
The asp code we have now is a total mess, full of bugs.
Sadly this proyect started before I could put my eyes on it. I know those urls are ugly, but asking the actual developer to rewrite the whole system to avoid them it's impossible right now. That is why I must learn about the Rewrite rules fast, in order to minimize the problems. Wish me luck.
AddType application/x-httpd-php .html
AddType application/x-httpd-php .asp
Then instead of the redirect you rewrite the url. There will be a little work for the developer to make the site link internally to the right url's but that should not be a big deal. What you are wanting to do should be the last thing you try when nothing else works. If you do this your site is going to have lots of problems with search engines for a while. Make sure your company knows that doing this will lose them traffic for a while.
A redirect sends "301", and a new URL for the content, back to the browser and the browser then requests the new URL in a new transaction. The server then delivers that content. Search engines will index the new URL too.
A rewrite takes the requested URL and translates it into an internal filename. The server fetches that internal file and delivers the content back to the browser without the browser seeing what that filepath actually is.