Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member Jase Wolf's Avatar
    Join Date
    Sep 2016
    Location
    United Kingdom
    Posts
    2
    Member #
    55153

    .htaccess extentionless url rewrites breaking folder redirects?

    Hi, on my sites, I'm wanting extentions to be removed, and then any extentioned requests get rewritten, also removing the trailing slash.

    By doing this, people can land on the page they want whether they put html, php, htm, or shtml (if there's more common extentions for web pages will be good to know) or no extention at all.

    Trouble is, folder/file redirects work fine before I place in the htaccess rules I have put together, but after, nothing I do works.

    Could anyone work out what is the culprit and what I can do instead to have the same effect but with working redirects?

    I asked this on my hosting provider's forums InstaFree.com, and one suggested it could be the ordering is wrong? He suggested to put redirects above these rules. Trouble is though, Cpanel redirect tool places redirect entries on the bottom, so that'd not be a solution.

    Here's the code. Thanks, Jase Wolf

    Code:
    # Rewrite urls to remove trailing slash
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /(.*)/$
    RewriteRule ^ /%1 [R=301,L]
    
    
    # Redirect http to https
    
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    
    # Rewrite files to extensionless urls
    
    RewriteRule ^([^/.]+)$ /$1.php [L]
    RewriteRule ^([^/.]+)$ /$1.html [L]
    RewriteRule ^([^/.]+)$ /$1.shtml [L]
    RewriteRule ^([^/.]+)$ /$1.htm [L]
    
    
    # Redirect external requests to extensionless urls
    
    RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ $1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^(.+)\.html([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.html$ $1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^(.+)\.htm([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.htm$ $1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^(.+)\.shtml([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.shtml$ $1 [R=301,L]

  2.  

  3. #2
    Junior Member Jase Wolf's Avatar
    Join Date
    Sep 2016
    Location
    United Kingdom
    Posts
    2
    Member #
    55153
    Right after some testing this is the culprit, had a bit of a feeling it was this as I was also having redirect issues just with the php rewriting I were using.


    Code:
    RewriteRule ^([^/.]+)$ /$1.php [L]
    RewriteRule ^([^/.]+)$ /$1.html [L]
    RewriteRule ^([^/.]+)$ /$1.shtml [L]
    RewriteRule ^([^/.]+)$ /$1.htm [L]



    Using this code instead fixes it


    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.*)$ $1.html
    [NC,L]RewriteCond %{REQUEST_FILENAME}.htm -f
    RewriteRule ^(.*)$ $1.htm [NC,L]
    RewriteCond %{REQUEST_FILENAME}.shtml -f
    RewriteRule ^(.*)$ $1.shtml [NC,L]



    So WOOOHOOOOOOOOOOOOOOOO, been trying to work this out for ages, and despite posting on four places, I work it out How fantastic lol
    Last edited by Jase Wolf; Sep 11th, 2016 at 05:07 PM.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 01:03 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com