Welcome to WebmasterWorld Guest from 54.196.232.162

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess to redirect www & retain dirs

     
3:56 am on Jan 31, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 7, 2005
posts:45
votes: 0


I have an issue with Google indexing some pages as:
mydomain.com/main/category/product/
instead of:
www.mydomain.com/main/category/product/

The software, with .htaccess, rewrites category.php as a directory based on the requested category name, like so:
/main/category/
Then for products, the same idea:
/main/category/product/

Ok, here's what I have currently in htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^main/([^/]*)([/]*)$ /category.php?cid=$1
RewriteRule ^main/([^/]*)/([^/]*)([/]*)$ /product.php?cid=$1&uid=$2

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule ^(.*) [mydomain.com...] [L,R=301]

With this setup, a request for:
[mydomain.com...]
redirects to:
[mydomain.com...]

Is there a way to preserve the structure? E.g.
[mydomain.com...]

For now, as a workaround, I've simply put a META Robots noindex dynamically on pages accessed in the last format shown above.

Any ideas?
Thanks in advance.

3:58 am on Jan 31, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


You should put the domain redirection rule first, so that it does not expose your internal rewrites.

Also, only one instance of "RewriteEngine on" is needed per .htaccess file.

Jim

5:01 am on Jan 31, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 7, 2005
posts:45
votes: 0


Thanks, that works perfect. I was hoping it would be something simple :)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members