ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

200 response duplicated

October 25, 2012 6:11pm

Subscribe [2]
  • #1 / Oct 25, 2012 6:11pm

    MikeCJ

    47 posts

    http://mysite.org/ and http://mysite.org/index.php are both returning a 200 response. How do I get a 301 redirect for http://mysite.org/index.php?

    I have this code in place in the .htaccess file:

    <IfModule mod_rewrite.c>
            RewriteEngine On
    
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/$1 [L]
    
            # If 404s, "No Input File" or every URL returns the same thing
            # make it /index.php?/$1 above (add the question mark)
    </IfModule>

    Please advise as to how I can avoid this duplication.

    Thanks,
    MikeCJ

  • #2 / Oct 29, 2012 10:54am

    Shane Eckert

    7174 posts

    Hey there MikeCJ,

    I am not sure why this is happening.

    Is there anything else in your htaccess file? Does this redirect take place if you remove the htaccess file out of the process? If it does not, then you may want to take a look at the Apache logs to see what is going on.

    Please let me know.

    Cheers,

  • #3 / Oct 29, 2012 11:45am

    MikeCJ

    47 posts

    I have removed various portions of the .htaccess file to check the result.

    When everything is removed from the file, http://mysite.org/ and http://mysite.org/index.php are both returning a 200 response.

    Both are returning a 200 response when the following code is inserted into .htaccess:

    <IfModule mod_rewrite.c>
            RewriteEngine On
    
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/$1 [L]
    
            # If 404s, "No Input File" or every URL returns the same thing
            # make it /index.php?/$1 above (add the question mark)
    </IfModule>

    And when ALL the original .htaccess code is inserted, both return 200 responses.

    I have tried doing a 301 redirect for /index.php/ in my hosting company’s CPanel, but that messes up all the internal links on my site.

    I contacted the hosting company and asked them to take a look at the Apache logs, and their reply was that everything looked fine. Unfortunately, I do not have the experience to analyze the Apache records.

    Please advise.

    Thanks,
    MikeCJ

     

  • #4 / Oct 29, 2012 4:48pm

    MikeCJ

    47 posts

    Shane,

    Would you take a look at the following changes I made in .htaccess?

    <IfModule mod_rewrite.c>
    
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    
    #Redirect www to non-www
    RewriteCond %{HTTP_HOST} ^www.mysite.org
    RewriteRule (.*) <a href="http://mysite.org/$1">http://mysite.org/$1</a> [R=301,L]
    
    #Code to add trailing slash
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ <a href="http://mysite.org/$1/">http://mysite.org/$1/</a> [L,R=301]
    
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{THE_REQUEST} !/system/.*
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
    
    # Standard ExpressionEngine Rewrite
    # ------------------------------
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    </IfModule>

    I searched through the forums some more and found this suggestion which I added to the above (which fixed the duplicate 200 response):

    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{THE_REQUEST} !/system/.*
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

    I also changed up the order. I am now getting a 200 response only from http://mysite.org/ Index.php is returning a 301 response. I am getting a 404 response for the following.

    index.htm
    index.html
    index.shtml
    index.asp
    default.asp
    index.aspx
    index.cfm
    index.pl
    default.htm

    I’m not getting any internal linking errors, so if you don’t see any errors I think I’m good to go.

    Thanks,
    MikeCJ

  • #5 / Oct 30, 2012 12:37pm

    Shane Eckert

    7174 posts

    Hey Mike,

    I will be honest with you. I see nothing wrong, but I believe htaccess is black magic. I have been Administrating Linux servers and Apache for over 10 years, and I still gate to touch htaccess files. Vodoo!

    If it is working for you now, then I say go with it. If you would feel better about things, I can have an Engineer look it over and let you know, but I think you are good to go.

    Cheers,

  • #6 / Oct 30, 2012 1:54pm

    MikeCJ

    47 posts

    Hey Shane,

    I have root access to my site but the hosting company said they don’t recommend a novice access it and in fact have many clients who understand Apache that don’t want access because a site can be easily wrecked.

    Unless you have another idea, I guess I’m stuck with .htaccess. My site scores in the low nineties on PageSpeed. I would like to make it perfect, but I don’t have the chops to do that.

    I’ve done about all I know to do with .htaccess. If you feel that an engineer might be useful please go ahead. But otherwise, we can close this thread.

    Thanks,
    MikeCJ

  • #7 / Oct 31, 2012 12:47pm

    Shane Eckert

    7174 posts

    Hey MikeCJ,

    Gotcha. If you need anything else, please just let me know.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases