homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

htaccess to redirect www & retain dirs

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

I have an issue with Google indexing some pages as:
instead of:

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

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:
redirects to:

Is there a way to preserve the structure? E.g.

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)

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.



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

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved