Forum Moderators: phranque
php_value display_errors onRewriteEngine On
RewriteOptions MaxRedirects=10
RewriteCond %{HTTP_HOST} ^(www\.)?webshop\.co\.uk$
RewriteCond %{REQUEST_URI} !^/shop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /shop/$1 [QSA,L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?webshop\.co\.uk$
RewriteRule ^(/)?$ shop/index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?website\.co\.uk$
RewriteRule ^shop/(.*)$ http://www.website.co.uk/$1 [QSA,L,R=301]
RewriteRule ^((urllist¦sitemap¦gss).*\.(xml¦txt¦xsl)(\.gz)?)$$1[L]
RewriteRule ^([^/]*)$ /hide/engine.php?file=$1 [QSA]
basically in the first section (which works) if the domain is webshop then it will redirect to the /shop directory on website.
the second section if it is a straight url of webshop it goes to the index page.
the third section is where my problem lies if a user clicks on an old link (eg www.website.co.uk/shop/c1/this-category) i need it to redirect to www.webshop.co.uk/c1/this-category
i have tested
^shop/(.*)$ http://www.website.co.uk/$1 [QSA,L,R=301]
SECONDLY
in the /shop/ directory i have another .htaccess file (below)
php_value display_errors onRewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?webshop\.co\.uk$
RewriteRule ^c([0-9]+)/[^/]+_all$ /shop/category.php?cid=$1&tp=1[QSA,L]
RewriteRule ^c([0-9]+)/[^/_]+$ /shop/category.php?cid=$1[QSA,L]
RewriteRule ^p([0-9]+)/[^/]+$ /shop/product.php?pid=$1[QSA,L]
RewriteRule ^brand/([0-9]+)/[^/]+$ /shop/results.php?brand=$1[QSA,L]
RewriteRule ^((urllist¦sitemap¦gss).*\.(xml¦txt¦xsl)(\.gz)?)$$1[L]
all the status bar links and hyperlinks look like this
www.webshop.co.uk/p2/this-product
www.webshop.co.uk/shop/p2/this-product
Within each group, you need "most specific" (i.e. affects the least number of URLs) listed first, and 'least specific' (i.e. affects the most number of URLs - catches anything not already actioned by the preceding rules) last.
Every redirect should contain the canonical domain in the target URL, as well as [R=301,L].
Rewrites should not accept URL requests for Duplicate URLs. That is, place a redirect from non-www to www before the rewrite. Don't let the rewrite capture both non-www and www URL requests.
Likewise, don't let trailing slash be optional as input URL to a rewrite. Set up a preceding redirect to 'fix' the URL to one format, before the rewrite kicks in.
You must add a required space before the [FLAGS] in most lines of code above.
Correct the code as detailed above and then post again, so that any remaining issues can be debugged.
[edited by: g1smd at 9:14 pm (utc) on Mar. 18, 2009]
i'm not sure i'm following this.
the third section
RewriteCond %{HTTP_HOST} ^(www.)?website\.co\.uk$
RewriteRule ^shop/(.*)$ http://www.website.co.uk/$1 [QSA,L,R=301]
RewriteRule ^((urllist¦sitemap¦gss).*\.(xml¦txt¦xsl)(\.gz)?)$$1[L]
RewriteRule ^([^/]*)$ /hide/engine.php?file=$1 [QSA]
seems to be working. except if i directly enter the url
http://www.website.co.uk/shop/c1/this-category
www.website.co.uk/this-page