The website in question is: sophostechnologies.com
https://sophostechnologies.com or sophostechnologies.com works fine and loads in SSL, HOWEVER, if I type www. or https://www. in front of the url name, I get too many redirects loop error.
My .htaccess file looks like this:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.sophostechnologies.com/$1 [R,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)\.(.*)$
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Google sitemap controller
RewriteRule ^(tmp/)?sitemap.xml$ tmp/sitemap.xml [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)(\.php([0-9]*)|\.json|\.xml|\.tpl|\.phtml|\.ini|\.inc|/)$ index.php?_p=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_p=$1 [QSA,L]
Any help is appreciated.
Related
Hi I am use Deployer to deploy a Craft CMS website. The site is symlinked to the directory called 'current'. I am using mod rewrite to remove the /current/public from the url in the document root like so:
RewriteEngine On
RewriteCond %{REQUEST_URI} !current/public/
RewriteRule (.*) /current/public/$1 [L]
And inside the current/public folder there is this htaccess to remove the index.php and create nice urls:
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
Edit - Test
The following works to force HTTPS but I end with urls looking like:
example.com/current/public/about etc
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
How can I adjust this to force the site to always use HTTPS?
This will redirected all http request to https.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www.)?yourdomainname.com
RewriteRule ^(.*)$ https://www.yourdomainname.com/$1 [R,L]
Hope this will help you
The following is what I managed to get working:
RewriteEngine on
RewriteRule ^(.*)$ current/public/$1
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
I'm attempting to canonicalization my URL. However, when adding the relevant code, it breaks my other rewrite rules which allows me to hide the .html/ .php. It works fine when landing on the homepage but when you go to a page with www. and a file path at the end of the URL the page redirects to the homepage without www.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
RewriteCond %{HTTP_HOST} ^www\.bespoke-apertures\.co.uk$ [NC]
RewriteRule (.*) https://bespoke-apertures.co.uk/$1 [R=301,L]
Have it like this in different order:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(bespoke-apertures\.co.uk)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [L,QSA]
Make sure to test this in a new browser to avoid old cache.
Try this to redirect without www :
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
I added some lines in my htacess file to redirect all http requests to https. Now when I type in a URL like: http://example.com/frames/view/4701362, it redirects to: https://example.com/index.php?q=frames/view/4701362. I can go to the page manually: https://example.com/frames/view/4701362 and the URL does not get changed.
I have Clean URLs set up
Htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
#some more stuff here, unrelated
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
Edit:
I tried reversing the Drupal index.php?q= line and the https lines like this...
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
But then my site did not load properly and said Page not found even at the homepage.
Thanks to #MikeRockett above, I was able to figure this out. In addition to his suggestion, I had to add [L,R=301] to the RewriteRule line.
<IfModule mod_rewrite.c>
RewriteEngine on
#some more stuff here, unrelated
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
I've been able to set up .htaccess to enable vanity urls on my website. However, I'm encountering into a problem when I try to clean other urls on my website. I would give the scenario and my current .htaccess below:
Currently wwww.mywebsite.com/john redirects to profile.php?user=john. In profile.php I check to see user john exist in my database if false I redirect to a custom 404.php page. This work very well. The problem arises when I try to have wwww.mywebsite.com/photo/abcdefg be interpreted as www.mywebsite.com/photo.php?m=abcdefg. For some reason it believes photo is the name of the user and then rewrites it as if its a vanity url. Please see my .htaccess file code below:
ErrorDocument 404 http://www.mywebsite.com/404
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC]
RewriteRule ^([^\.]+)$ profile.php?username=$1 [L]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteRule ^ HTTP%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
You need to do your redirect before any internal routing. Then, you need to explcitly match against /photo before you route to profile and change the .php -f:
ErrorDocument 404 http://www.mywebsite.com/404
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteCond %{HTTP_HOST} !^(.*)\.(.*)\. [NC]
RewriteRule ^ HTTP%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^photo/(.+)$ /photo.php?m=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^\.]+)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ /profile.php?username=$1 [L]
I'm trying to set up a local instance of a php site working in a server, in the "/" directory. My local instance will work in my development environment in a "/subdirectory/".
I'm trying to translate .htaccess to adapt to this, but I always get a 404. This is original .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
And these are my tries:
RewriteEngine on
RewriteBase /mylocaldirectory/
# Not in local! RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# Not in local! RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-nice-url$ /index.php?p=ugly_url
Also
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)my-nice-url$ /index.php?p=ugly_url
Thank you
If i got you right, you want make a user friendly url, i do it like this:
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=$2 [L]
or
RewriteRule ^(.*)/(your-nice-url)$ ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=what-ever-you-need [L]
Hope it help you.