manchuwok Posted December 17, 2009 Share Posted December 17, 2009 Hi all, First time poster here! I have run into a problem while trying to implement a 301 redirect via my site's .htaccess file. I have used 301 redirects with success before, but this is the first time dealing with this problem. I want http://www.mysite.com to redirect to http://mysite.com. My 301 redirect does send the user correctly, but the problem is that it displays this URL: http://mysite.com/index.php?/ In contrast, if I type http://mysite.com directly into the browser, I do not see this /index.php?/ To make things easier, here is a look at my .htaccess file: RewriteEngine on RewriteCond $1 !^(ADMIN|images|tools|themes|favicon\.ico|robots\.txt|index\.php) [NC] RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{HTTP_HOST} ^www.mysite.com [NC] RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301] Any thoughts on what I am doing wrong here?? Thank you!! Quote Link to comment https://forums.phpfreaks.com/topic/185520-php-problem-with-301-redirect/ Share on other sites More sharing options...
zq29 Posted December 18, 2009 Share Posted December 18, 2009 It looks like your first rule is interfering, as it matches the requested page after redirecting. I'm not 100% sure on this, but adding a pattern at the end of your RewriteCond might fix this as the resulting page mysite.com doesn't start with any of the things you're checking for, but you do want something after the domain name to trigger the inclusion of /index.php/$1 RewriteEngine on RewriteCond $1 !^(ADMIN|images|tools|themes|favicon\.ico|robots\.txt|index\.php).+ [NC] RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{HTTP_HOST} ^www.mysite.com [NC] RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/185520-php-problem-with-301-redirect/#findComment-980192 Share on other sites More sharing options...
manchuwok Posted December 18, 2009 Author Share Posted December 18, 2009 Semi, Thank you for the reply! Your guess that the first rule was interfering was spot on - before adding a pattern, I tried simply switching the order of the rules, and it totally fixed the problem. Thank you very much! Ben Quote Link to comment https://forums.phpfreaks.com/topic/185520-php-problem-with-301-redirect/#findComment-980216 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.