Jump to content

PHP problem with 301 Redirect


manchuwok

Recommended Posts

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!!

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.