So in my htaccess file for a Wordpress site I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
I want all urls whatever entered to go to https://example.com (https, no www.)
At the moment this works well here:
http://example.com = https://example.com
www.example.com = https://example.com
However when on a page it doesn't work:
http://example.com/page/ = example.com/page/
www.example.com/page/ = example.com/page/
How can I make this go to the https version?
Change you htaccess file to below and it will work for you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^$ https://example.com/? [L,R=301]
</IfModule>
You can use:
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
You can try using this in your .htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [NE,L,R=301]
This seems to have done to the trick...
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Related
I have the following redirects in htaccess Wordpress is installed in home folder The site must redirect an example.com (without www) and with https
The wordpress installation is in / home
And I don't know how to fix it. Any suggestions? Thank you !!
RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /home/$1
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(/)?$ home/index.php [L]
# BEGIN SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^example\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
# END SSL```
You can't force subfolder or subdomain to redirect to https
for https redirection just use this
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
For Subfolder
RewriteRule ^/?(.*) https://%{SERVER_NAME}/home/$1 [R,L]
also you can use the default .htaccess for redirection
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
For a main domain (.nl) everything is forced over https and www.
However there is a small bug with parked domain .be
when accessed like https://domain.be/example the www. is not added.
In all other cases it is working.
.htaccess i have so far is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)$ [NC]
RewriteRule ^(.*)$ https://www\.%1/$1 [R=301,L]
</IfModule>
Any ideas would be welcome!
Might want to check this
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have a site with Wordpress. I need some single page to redirect HTTPS
I get code form stackoverflow and put in .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /online-order-auto [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/online-order-auto [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com\.swtest\.ru$
RewriteRule ^(.*)$ http://www.site.ru/$1 [L,R=301]
The browser wrote "ERR_TOO_MANY_REDIRECTS".
I cant understand whats a problem
Try this. I've been looking all over and this is the only way I could make it work...
#non-www. http to www. https
RewriteCond %{ENV:HTTPS} !on
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
#non-www. https to www. https
RewriteCond %{ENV:HTTPS} on
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
I have a wordpress website in /subfolder.
In the root, there is a folder called /reports/
I need to rewrite url so /reports/ becomes /reports/index.php but wordpress is changing path to be /reports/. (and I get page not found)
This is my .htaccess:
RewriteEngine on
RewriteBase /
# Only apply to URLs that aren't already under /wordpress2.
RewriteCond %{REQUEST_URI} !^/wordpress2/
# Rewrite all those to insert /wordpress2.
RewriteRule ^(.*)$ /wordpress2/$1
# Redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?website.com.au$
RewriteRule ^(/)?$ wordpress2/ [L]
RewriteCond %{HTTP_HOST} ^/reports$ [NC]
RewriteRule ^(.*)$ /reports/index.php/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^freeloancalculator.com.au/reports$ [OR]
RewriteCond %{HTTP_HOST} ^www\.reeloancalculator\.com\.au/reports$
RewriteRule ^/?$ "http\:\/\/reeloancalculator\.com\.au/reports/index.php\/" [R=301,L]
I hadn't tried this, but I think this will help you..
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/index.php /reports=$1/ [NC]
By adding ./ /index.php, it fixes the issue
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
</IfModule>
# END WordPress
I was hoping someone could take a look at my htaccess setup and tell me if I'm doing something wrong. Every time I try to add in one of the numerous formats I've found to redirect my page to www, I get a redirect loop.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The above works, but it goes to the base page with no www.
I've tried the following setups, and none work.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This is the code I add to the default .htaccess file that is setup with WordPress. To add the www I use:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]
Make sure you update WordPress Address (URL) [under general settings] as well to include www.