Cheepnis Posted April 14, 2011 Share Posted April 14, 2011 I have my store at www.mysite.com/store/catalog/index.php Everything in the store works great. I have www.mysite.com/index.html that does a meta redirect to www.mysite.com/store/catalog/index.php for people arriving at the root. It works, but... It's slow and I understand SEO would prefer a 301 redirect, so I'm editing my .htaccess file. Up to this point, I have only had used rewrite to add "www" to anybody coming in without it: RewriteEngine on # RewriteCond %{HTTP_HOST} ^mysite\.com [NC] # ReWriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] However, I would like to also have anybody arriving to www.mysite.com to be 301 redirected immediately to www.mysite.com/store/catalog/index.php I then tried to add the following below it, but it breaks my site: RewriteCond %{HTTP_HOST} ^www\.mysite\.com [NC] RewriteRule * http://www.mysite.com/store/catalog/index.php [R=301,L] Any help here would be most appreciated! Link to comment Share on other sites More sharing options...
MrPhil Posted April 14, 2011 Share Posted April 14, 2011 Your code 1) has an invalid RewriteRule pattern, and 2) sends all visitors (including old saved links) to the main entry. RewriteCond %{REQUEST_URI} !^/store/catalog [NC] RewriteRule ^(.*)$ /store/catalog/$1 [R=301,L] This assumes that your store (say, the main index.php) is in /store/catalog. Any URL coming in without /store/catalog leading off the URI will get /store/catalog added to it. As you're doing a 301 redirect (tell everyone that they should remember the new address) and aren't hiding the fact that you're redirecting, you might as well leave your configure.php files showing "/store/catalog" rather than "/". The store will work either way, but it's silly to send a bad URL (in an internal link) to your customer's browser, have the browser send in the bad URL, have your server bounce back the good URL, have the browser resubmit with the good URL, and then serve up the page. Just send out the correct URL in the first place by having correct configure.php files. Link to comment Share on other sites More sharing options...
Cheepnis Posted April 14, 2011 Author Share Posted April 14, 2011 Thanks for your help Phil, but when I use your suggestions (and commenting out the prior rewrites that add the "www") it returns with a browser (FF) error that redirection cannot happen. Here's what I currently have, but if I remove the META redirect in the root index.html (by removing the index.html file), the store works fine when going to mysite.com, but returns a 403 for going to www.mysite.com. RewriteEngine on RewriteCond %{HTTP_HOST} ^mysite.com [NC] RewriteCond %{HTTP_HOST} ^(www.)?mysite.com [NC] RewriteRule ^(.*)$ http://www.mysite.com/store/catalog/$1 [L,R=301] It seems like what I'm looking for should be simple enough. What I want is for it to say "when somebody goes to either mysite.com or www.mysite.com, send them permanently to www.mysite.com/store/catalog instead" in such a way that not having an index.html in the root doesn't matter. Link to comment Share on other sites More sharing options...
Jack_mcs Posted April 14, 2011 Share Posted April 14, 2011 However, I would like to also have anybody arriving to www.mysite.com to be 301 redirected immediately to www.mysite.com/store/catalog/index.php It's a mistake having it redirect to index.php. In fact, the code should be added to remove that from the urls. See here for the changes you should make. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
MrPhil Posted April 15, 2011 Share Posted April 15, 2011 Your .htaccess file says "if the domain is mysite.com AND (the domain is mysite.com OR it is www.mysite.com), redirect all visitors to http://www.mysite.com/store/catalog/index.php". That will work for mysite.com, but www.mysite.com won't match the conditional and doesn't get redirected (and with no index.html, you get a 403). For better indexing, I would keep the non-www -> www rewrite. Depending on your host's exact configuration, you may or may not be allowed to do the following: RewriteEngine On RewriteCond %{HTTP_HOST} ^mysite\.com RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] RewriteCond %{REQUEST_URI} !^/store/catalog [NC] RewriteRule ^(.*)$ /store/catalog/$1 [R=301,L] The first part makes any URL consistent with the www.mysite.com domain (better SE indexing that way). The second part sends back any URI that doesn't start with /store/catalog and says "use an address that starts with /store/catalog". If your host allows only one 301 redirect at a time, try this: RewriteEngine On # www.mysite.com/store/catalog leave alone RewriteCond %{HTTP_HOST} ^www\.mysite\.com RewriteCond %{REQUEST_URI !^/store/catalog [NC] RewriteRule ^(.*) http://www.mysite.com/store/catalog/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^mysite\.com RewriteCond %{REQUEST_URI} ^/store/catalog [NC] RewriteRule ^(.*)$ http://www.mysite.com/store/catalog/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^mysite\.com RewriteCond %{REQUEST_URI} !^/store/catalog [NC] RewriteRule ^(.*)$ http://www.mysite.com/store/catalog/$1 [R=301,L] Link to comment Share on other sites More sharing options...
Cheepnis Posted April 15, 2011 Author Share Posted April 15, 2011 Phil, I tried both suggestions (after stripping out everything else in my htaccess and clearing my cache) and they both return this error message: The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete. Link to comment Share on other sites More sharing options...
MrPhil Posted April 16, 2011 Share Posted April 16, 2011 Did you modify my code at all (except for the domain name), like you did before? Link to comment Share on other sites More sharing options...
Cheepnis Posted April 16, 2011 Author Share Posted April 16, 2011 Did you modify my code at all (except for the domain name), like you did before? No, except for adding a closing brace that was left out of line 2 in the second example and using my domain, I cut and pasted them exactly. Link to comment Share on other sites More sharing options...
MrPhil Posted April 17, 2011 Share Posted April 17, 2011 Sorry about the typo. If you're running exactly what I gave above (with typo fixed -- you can change ^(.*) to ^(.*)$ too if you wish), I do see a bug in the second stanza. Change it from RewriteCond %{HTTP_HOST} ^mysite\.com RewriteCond %{REQUEST_URI} ^/store/catalog [NC] RewriteRule ^(.*)$ http://www.mysite.com/store/catalog/$1 [R=301,L] to RewriteCond %{HTTP_HOST} ^mysite\.com RewriteCond %{REQUEST_URI} ^/store/catalog [NC] RewriteRule ^store/catalog/?(.*)$ http://www.mysite.com/store/catalog/$1 [R=301,NC,L] You were probably getting http://www.mysite.com/store/catalog/store/catalog/......./xxxxx with the original. Sorry! Link to comment Share on other sites More sharing options...
Cheepnis Posted April 18, 2011 Author Share Posted April 18, 2011 Nope - still didn't work. I'm pretty much giving up at this point. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.