It's the first time I've used 123-reg for website hosting (I usually use another host). The site has an SSL certificate and the htaccess file redirects to https:// HOWEVER... it's not removing the html extensions from the pages (it DID remove them when it was http:// )
123-reg say it's something I'm doing or not doing at my end, but the following htaccess code works just fine with my other host, just not 123-reg.
htaccess code I'm using (which also directs to https:// )
RewriteEngine On
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Here's the website url: https://buyrich.co.uk/
I think I've fixed it with this code from that post, thank you:
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteCond
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
Related
I have a website with https://example.com, http://example.com, https://www.example.com and https://www.example.com working fine.
Now I want that regardless of which one you type, it redirects to https://www.example.com. I am using the code below in my .htaccess (and tried many more), but after doing the redirection in the browser the page doesn't load, giving error "Too many redirects". I tried of course deleting cache.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Since my hosting is Heroku, which has special rules, any of the other solutions didn't work for me.
The following code in .htaccess worked like a charm:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I have something Similar issue the bellow code solve problem for me
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^[DOMAIN HERE]$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Note: Replace[DOMAIN HERE]Should be Replaced With you domain
I have a problem with forcing HTTPS on my domain, my htaccess file on root of the web has following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)$ $1.php [L]
This works perfectly on http and https protocols, but website is not forced to https, when visiting over http. So I added later to my htaccess code that force https, and the result was following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+)$ $1.php [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But the website stopped work at all. Do you know why? And how can I fix it? Thank You so much.
Best Regards
I do not have a deep understanding of .htaccess files, but this worked for me and might help you too. Handle the redirect to https first, then remove the .php from the filename.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I have an Angular 5 based website and I need to implement Force SSL with www in this website.
So basically I need any variation of domain like http://example.com or example.com or www.example.com etc.. all to redirect at https://www.example.com
The current used .htaccess files is as follows :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
I tried solutions from multiple resources, example of one such is Force SSL and WWW together using htaccess, by adding the mentioned code at the bottom of above code, but no luck.
Any help is much appreciated.
Have You tried this:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
You can use this also
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I've installed Drupal 7 to a sub-directory on my server and used .htaccess mod_rewrites to fix most of the URL pathing issues, I'm now looking for a way to strip the sub-directory from the URL when it's explicitly requested.
To be clear, the site can be accessed from 'example.com' and the internal links work fine, but I'm looking to prevent requests to 'example.com/sub/file' from working, Ideally with a 301 back to 'example.com/file'.
My .htaccess at the moment looks like this:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ sub/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -f
RewriteRule .* sub/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* sub/index.php?Q$0 [QSA]
Have you tried adding:
Redirect 301 /\/sub/file http://www.example.com/file
to your .htaccess?
I'm having an issue with .htaccess where I have managed to successfully rewrite the URLs but the content is no longer loading.
The following is my htaccess file.
I'm aiming for all my .html pages (the site is made of .html static pages) to have their extensions removed. However, I require the .html URLs to 301 redirect to the new URL's so that my SEO does not take a hit from these changes.
Example:
Original: www.example.co.uk/page.html
Desired: www.example.co.uk/page/
It is important that the original URL redirects the new URL's though.
Options +FollowSymLinks
RewriteEngine on
# REDIRECT yourdomain.com TO www.yourdomain.com
RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]
RewriteRule (.+)\.html?$ http://www.example.co.uk/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(([^/]*/)*[^/.]+)$ $1.html [L]
I have tried the htaccess above and I've also tried the variation below, but neither has worked as desired. Any help would be much appreciated.
Options +FollowSymLinks
RewriteEngine on
# REDIRECT yourdomain.com TO www.yourdomain.com
RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]
RewriteRule (.+)\.html?$ http://www.example.co.uk/$1/ [R=301,L]
You need to change 2 things.
Add this right after your redirect to prevent a redirect loop:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
change the last rule to this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1\.html -f
RewriteRule ^ /%1.html [L]