Welcome Guest, Not a member yet? Register   Sign In
Use .htaccess to avoid broken links after removing URL suffix
#1

[eluser]Phil Sturgeon[/eluser]
Right, I removed .html from the URL suffix config item and now the old URL links are broken (from Google, bookmarks, etc).

So far my .htaccess looks like this:

Code:
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on

    # BROKEN RULE SECTION
    # .html was remove in v0.9.6 so this will help your URL's work after the upgrade. Will be removed in v1.0
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)\.html$ $1 [L,R=301]
    # END OF BROKEN RULE SECTION

    RewriteRule modules/(.+)/controllers/(.+)\.php$ /index.php/$1/$2 [L,R=301]
    RewriteRule controllers/(.+)\.php$ /index.php/$1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}!-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
#2

[eluser]Phil Sturgeon[/eluser]
Got it mostly working with this:

Code:
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    
    # Redirects direct controller views to the right URL
    # Not so much for security, done for Coda previews
    RewriteRule modules/(.+)/controllers/(.+)\.php$ /index.php/$1/$2 [L,R=301]
    RewriteRule controllers/(.+)\.php$ /index.php/$1 [L,R=301]
    
    # Remove the .html extention if present (and not an existing file)
    RewriteCond %{REQUEST_URI} ^(.*)\.html$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)\.html$ index.php/$1 [L]

    # Send request via index.php (again, not if its a real file or folder)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Problem is, it wont 301 redirect. If I put ,R=310 into the 2nd last rule flag then it breaks.




Theme © iAndrew 2016 - Forum software by © MyBB