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.

Help with .htaccess issue

August 04, 2011 6:37pm

Subscribe [1]
  • #1 / Aug 04, 2011 6:37pm

    rt30000

    125 posts

    I am getting ready to take a new site live and want to do a 301 redirect on old pages that no longer exist. I have a set of .htaccess rules I use on every site to remove index.php and it has always worked great, but I think I have a conflict somewhere. URLs I want to rewrite only work if you manually add index.php into the URL. For example…

    RewriteRule /specifications.php <a href="http://google.com">http://google.com</a> [I,RP,L]

    ...does not work (just displays home page as I have no 404 page designated), but if you insert index.php in front of the URL it will redirect properly.

    Here is my .htaccess I use on every site

    <IfModule mod_rewrite.c>
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine on
    RewriteBase /
    
    
    # Update requests for old site pages to new location
    # ----------------------------------------------------------------
    RewriteRule /contact.php /contact [R=301] 
    RewriteRule /history.php /history [R=301] 
    RewriteRule (/test/specifications.php) /products [I,R,L] 
    
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{THE_REQUEST} !/sys_ezgutter/.*
    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>
  • #2 / Aug 04, 2011 7:27pm

    rt30000

    125 posts

    Further testing, I have found it works when the URL you are matching does not contain a slash or dot. For example this works…

    RewriteRule (specifications) /products [I,R,L]
    but this will not
    RewriteRule (test/specifications.php) /products [I,R,L]

    I have tried escaping the slashes and dots to no avail.

  • #3 / Aug 04, 2011 7:45pm

    rt30000

    125 posts

    RESOLVED, the following rules seem to work…

    RewriteRule (^contact.php) /contact [I,R=301,L] 
    RewriteRule (^history.php) /history [I,R=301,L] 
    RewriteRule (^test/specifications.php) /products [I,R=301,L] 
    RewriteRule (^pdf/spec1.pdf) /products [I,R=301,L]
    RewriteRule (^pdf/spec2.pdf) /products [I,R=301,L]
    RewriteRule (^pdf/spec3.pdf) /products [I,R=301,L]
    RewriteRule (^pdf/spec4.pdf) /products [I,R=301,L]
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases