Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite with built in 301 redirect Question for SEO

mod_rewrite with built in 301 redicect for SEO

         

jzbiz

9:15 pm on Mar 16, 2010 (gmt 0)

10+ Year Member



Hi All,

This is my first post at Webmaster World and based on your reputation, I'm excited to receive some feedback.

For SEO purposes I want all versions of my URL <www vs http version vs /index.html etc) at my website to refer to a single canonical URL.

Specifically I'm trying to figure out how to do a mod_rewrite that 301 redirects all versions of the same URL to the http://example.com version. Similarly, I'm trying to figure out an .htaccess rule that makes any version of any page on my site also 301 back to the http://example.com/page.html version.

I'm quite new to this and the only solution I've found thus far is writing 301 redirects for each version of each page that I want to redirect. The problem with this is that it is extremely cumbersome with regard to creating new pages. Who wants to have to modify the .htaccess file each and every time they create a new page right?

I'm hoping you can help me with this as I'm sure you've dealt with this issue before. I'm really looking forward to receiving some feedback on this.

Many Thanks.

jdMorgan

9:33 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi jzbiz, and Welcome to WebmasterWorld!

Two suggestions:

First, use the power of Regular Expressions. It is likely that you need only two or three rules at most.

Second, avail yourself of the resources here. We have an Apache Forum Library with links to previous discussion and tutorial threads, an Apache Forum Charter with links to resources and some notes on how to get the most from this forum, and a site search facility which can be used to find previous threads on topics similar or identical to your own.

Also, note that the mod_rewrite RewriteRule and mod_alias Redirect and RedirectMatch directives are all activated based on the URL in the incoming HTTP request from the client (browser or search robot). Therefore, no meaningful discussion of these directives is really possible without a thoroughly-representative (but concise) list of requested URLs and their desired dispositions.

Please also note that we use and generally allow the use only of "example.com" and "www.example.com" as domain names, both to deter solely-promotional posts and to protect the sites being discussed here (which are often operating in a compromised position security- and search-ranking-wise, and would likely be better off without undue attention from troublemakers until these issues are corrected).

Links to the resources I mentioned are available at the top of this page. By all means, post specific questions back here.

Jim