I would like that the .htaccess don't add the SSL on the home link
http://domain.com
but on every other links in the website
https://domain.com/folder/index.html
So only the home page would not be secure. What the best .htaccess config for that ?
Thanks
Use RewriteRule to match that anything is present beyond the / and if matched, rewrite to SSL:
RewriteEngine On
# If ssl is not already active
RewriteCond %{HTTPS} !=on
# .+ matches one or more of any character... An empty string would not match
RewriteRule ^(.+)$ https://%{HTTP_HOST]}%{REQUEST_URI} [L,R=301]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.+$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} =on
RewriteRule ^$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Related
I added an SSL to my site and have the following htaccess file in place to redirect:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^(.*)$ "https://example.com/$1" [R=301,L]
</IfModule>
This covers almost everything, so http://www.example.com, http://example.com, and example.com all forward to https://example.com. However, there is one scenario where it does not. If I enter https://www.example.com, it does not redirect to https://example.com and I get a security certificate error. Looking for a solution. Thank you in advance.
cdr6545
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymlinks
# To redirect from www to non www (Rewrite www.example.com → example.com)
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http%{ENV:protossl}://%1/$1 [R=301,NE,L]
# Redirect HTTP to HTTPS automatically (only if not in localhost)
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
I have implemented the following code in the .htaccess file:
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteCond ${HTTPS} !=on
RewriteRule ^(page1\.php|page2\.php)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
This redirects page1.php and page2.php to https. However, I want to make sure that if the user navigates to any other page from the https page, they ho to http:// (and not remain on https://).
How can I do this?
Any help would be much appreciated!
You can use:
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteCond ${HTTPS} off
RewriteRule ^(page1\.php|page2\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond ${HTTPS} on
RewriteRule !^(page1\.php|page2\.php|\.css)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I need a way to add index.htm at end of url.
For example:
www.example.com/folder1/folder2 AND
www.example.com/folder1/folder2/
must be redirected internally to www.example.com/folder1/folder2/index.htm (this must apply for any number of folders/subfolders)
My htaccess (at root) so far looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteBase /
#
# some 301 REDIRECTS here
#
# rewrite non-www into www
# after all redirection rule AND before any rewrite rule
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#
# rewrite rules below here
#
Any way to fix this?
Thank you.
EDIT:
- All urls come from rewrite rules - there are no actual folders in site.
- Typing www.example.com/folder1/folder2 in my browser, only get a 404 page not found. I need it to redirect to www.example.com/folder1/folder2/index.htm (there is a rule creating this url)
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.htm$ [NC]
RewriteRule ^(.*?)/?$ /$1/index.htm [L,R=301]
Do you mean you want to REDIRECT /folder1 and /folder1/ into /folder1/index.htm, and /folder1/folder2 and /folder1/folder2/ to /folder1/folder2/index.htm, and /folder1/folder2/folder3 and /folder1/folder2/folder3/ to /folder1/folder2/folder3/index.htm
RewriteCond %{REQUEST_URI} ^/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /%1/index.htm [R]
RewriteCond %{REQUEST_URI} ^/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /%1/%2/index.htm [R]
RewriteCond %{REQUEST_URI} ^/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /%1/%2/%3/index.htm [R]
I am trying to redirect my site from non-www to www. My site is at [http://www.alennuskoodit.us]. I try to make it so that all requests without www would be redirected to www. Normal stuff so far.
However, if I go to http://alennuskoodit.us I end up here: http://www.alennuskoodit.us/index.php?qstr=http://www.alennuskoodit.us
This is the .htaccess:
Options +FollowSymLinks
Options +Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# going to install folder
RewriteCond %{REQUEST_URI} (.*)/install/?$
RewriteRule ^(.*)$ %1/install/index.php [NE,R,L]
# going to Admin folder
RewriteCond %{REQUEST_URI} (.*)/admin/?$
RewriteRule ^(.*)$ %1/Admin/index.php [NE,R,L]
# working with client side
RewriteRule ^(.*)/$ index.php?qstr=$1 [L]
</IfModule>
This is what I tried, which doesn't work:
RewriteCond %{HTTP_HOST} ^alennuskoodit.us [NC]
RewriteRule ^(.*)$ http://www.alennuskoodit.us/$1 [R=301,NC,L]
How could I redirect all queries to http://alennuskoodit.us to http://www.alennuskoodit.us so that I would not end up breaking the other rewrites?
Place your new rule before all the other rules i.e
Options +FollowSymLinks
Options +Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} ^alennuskoodit.us$ [NC]
RewriteRule ^(.*)$ http://www.alennuskoodit.us/$1 [R=301,NC,L]
#other rules here
and it should prevent the qstr= param
Step1= You Must Use This Code In htaccess File To Preferred www Version:
RewriteCond %{HTTP_HOST} !^(.).YourDomain.com$ [NC] RewriteRule ^(.)$ http://www.YourDomain.com/$1 [R=301,L]
Step2= You Must Setting Your Preferred Domain In Google WebMaster Tools :
Open up your webmaster tools and click “Settings” right below “Configuration”. To the right look for the “Preferred Domain” and select which domain you prefer With www Or Not.
Is there any way I can redirect my urls to only use http://www.domain.com instead of http://domain.com?
Here's my htaccess but doesnt work:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
# RewriteBase /test/
Options +FollowSymlinks
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
#redirec
#detect urls without www
RewriteCond %{http_host} ^thehotelinventory.com [NC]
#redirect to www, does not work though
RewriteRule ^(.*)$ http://www.thehotelinventory.com/$1 [R=301,L]
AddHandler php5-script .php
If you need to redirect from non-www to www, then redirect to HTTPS for certificates like THAWTE that dont support www non-www on SSL 123.
RewriteEngine On
#non-www to www
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
#Redirect to HTTPS before www redirect
RewriteEngine on
RewriteCond %{HTTPS}
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Thanks to Brasil na Web Dev. Guys.
a simple answer can be found here: http://snippets.dzone.com/posts/show/2264