Use code force https with www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [OR]
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
How do I make the url below work both with WWW and without WWW
https://example.com/license/get_license.php
https://example.com/license/verified_license.php
Resolution
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/license/get_license\.php$
RewriteCond %{REQUEST_URI} !^/license/verified_license\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com [OR]
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Credits: Hosting Webfaction
Related
This code below for rewrite/redirect from localhost/moneyworld/exchange?title=BTC_PMUSD to localhost/moneyworld/BTC_PMUSD but i want to rewrite/redirect from www.domain.com/exchange?title=BTC_PMUSD to www.domain.com/BTC_PMUSD Without also /moneyworld/
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(moneyworld)/exchange\?title=([^\s]*)\s [NC]
RewriteRule ^ /%1/%2 [NE,QSD,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /moneyworld/exchange?title=$2 [L]
Thanks
The problem was that i was forwarding exchange.php to exchange after the url rewrite rules so simply the code below solved it
RewriteEngine ON
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/exchange\?title=([^\s]*)\s [NC]
RewriteRule ^ /%1 [NE,QSD,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /exchange?title=$1 [L]
Good day. I have a website called with sub.domain.co.id and now I want to redirect it to https://sub.domain.co.id.
I'm using codeigniter and this what i change in my .htaccess
Before .htaccess look like this
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
then I change it to ref(redirecting https://domain.com to https://www.domain.com)
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^http://. [NC]
RewriteRule ^ https://sub.domain.co.id%{REQUEST_URI} [R=301,L,NE]
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
but no help. the URL still use http. How can i achieve that?
try this and see. (index.php will removed too)
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub.domain.co.id [NC]
RewriteRule ^(.*)$ https://www.sub.domain.co.id/$1 [L,R=301]
didn't test. 95% Sure. Not the 100%
I have a simple .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]
and now would like to add redirect from all www cals to non www
how to combine it with my file?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Add this to the top of your file (right below RewriteEngine On:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://$1/$1 [L,R=301]
I am trying to force ssl on certain urls using the following .htaccess on apache FastCGI. But the problem is when I try to browse http://[hostname]/basket it redirects to http://[hostname]/index.php?/basket instead of https://[hostname]/basket. Below is the code. I am stuck with this please help
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond $1 (checkout|basket)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond $1 !(checkout|basket)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
This issue has been resolved: below is the code if anyone else having the same issue:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 (checkout|basket)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !(checkout|basket)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
I have the follow .htaccess and it work good.
from http://us.domain.org/detail.php?id=1234 to
http://us.domain.org/category/city/computer-1234
but if I add:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /detail.php?id=$1 [L,QSA]
It does not work..How can I do?
from http://us.domain.org/detail.php?id=1234 to http://us.domain.org/category/city/computer-1234
Change your last rule to:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/-]+)-([^/]+)/?$ /detail.php?id=$4 [L,QSA]