.htacess error
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.netsentries.com
RewriteRule ^(.*)$ http://netsentries/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Error only comes when I add this line.
RewriteCond %{HTTP_HOST} ^www.netsentries.com
RewriteRule ^(.*)$ http://netsentries/$1 [R=301,L]
I have to add it because my site is not loading with www now. I want to make it load.
Use this code and your htaccess problem will be solved:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# no www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and if you have problem loading your site with www it is because of loosing www CNAME record from your website's host. You should check the nameservers from "DNS zone editor" of your websites hosting package and adding required records for www like this:
NAME:www.yoursite.com. TTL:14400 TYPE:CNAME RECORD:yoursite.com.
this will cause your website to work in both with and without www.
Try this once
RewriteCond %{HTTP_HOST} ^www\.netsentries\.com
RewriteRule ^(.*)$ http://netsentries.com/$1 [R=301,L]
Related
I have a client who has an http SEO'ed wordpress site, with https AdWords static html landing pages (I know - don't ask).
They want to 301 all non-www to www. I tried the following htaccess code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
This works great for getting all URLs redirected to www from non-www. However it also changes all https URLs to http.
How can I get it so that all non-www redirect to www, but http and https are NOT affected.
For example:
http://example.com/seo-page -> http://www.example.com/seo-page
and
https://example.com/ppc-page -> https://www.example.com/ppc-page
Thanks
EDT:
Existing .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* - [E=CANONICAL:http://%{HTTP_HOST}%{REQUEST_URI},NE]
RewriteCond %{HTTPS} =on
RewriteRule .* - [E=CANONICAL:https://%{HTTP_HOST}%{REQUEST_URI},NE]
</IfModule>
Try this :
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)
RewriteCond %{HTTPS} !=on
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} =on
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Save .htaccess and try this :
<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\.)
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS}:s on:(s)
RewriteRule .* - [E=CANONICAL:http%1://www.%{HTTP_HOST}%{REQUEST_URI},NE]
RewriteCond %{HTTP_HOST} ^(www\.)
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS}:s on:(s)
RewriteRule .* - [E=CANONICAL:http%1://%{HTTP_HOST}%{REQUEST_URI},NE]
</IfModule>
If you are using WordPress then you don't need to add any code in .htaccess file. You can redirect entire site by entering www or nonwww url in settings.
Login to wp-admin
Then hit settings button and visit in
the 3rd field name (WordPress Address (URL)) enter your URL where you want to redirect website. and paste the same URL in next field name (Site Address (URL))
and then Hit Save button.
Congratulation your website redirected successfully.
This works for rewriting all requests to the index.php located in my root folder, which works for example.com/1/2/3/4/5/...
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ / [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.mallzones\.com$
RewriteRule (.*) /%{REQUEST_URI}
I am trying to figure how to rewrite the wildcard subdomains as well. The wildcard should be prepended to the path. How do I modify these rules to accomplish the following url scheme.
example.com/1/ is equal to 1.example.com
example.com/1/2 is equal to 1.example.com/2
example.com/1/2/3 is equal to 1.example.com/2/3
example.com/1/2/3/4 is equal to 1.example.com/2/3/4
I've already created the A record in my DNS zones. What do I do next?
ANSWER: kudos to #CRIMSON 501
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ / [L]
Let me understand. Are you asking how to make it so that when a user navigates to example.com/1/ they are rerouted to 1.example.com?
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).example.com [NC]
RewriteRule (.*) http://example.com/ [L]
</IfModule>
To have a silent redirect the last line should be:
RewriteRule (.*) /index.php/or/whatever/you/need [L]
Just edit the links to what you need!
I have the Q2A script installed http://www.question2answer.org/
I have non-www. & non-https redirecting to www & https perfectly but, somewhere within the htaccess code it's redirecting my add-on domain http://addon-domain.com to https://www.main-domain.com/addon-domain.com/
I suspect it's something to do with the following but, have no idea how to edit it correctly:
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Here's the whole code:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# redirect any domain other than www.main-domain.com to www.main-domain.com
RewriteCond %{HTTP_HOST} !^www\.main-domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
# force https on www.main-domain.com
RewriteCond %{HTTPS} ^off
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
edit: This question is now moot as the whole site will be served using HTTPS
My .htaccess is causing a redirect loop.
I need all three sections to work, the purpose of each is in the comment.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Force HTTPS for /book unless dev or already there
RewriteCond %{HTTP_HOST} !^dev\.
RewriteCond %{HTTPS} !^on$
RewriteRule ^book https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Force www prefix unless dev or already there
RewriteCond %{HTTP_HOST} !^dev\.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ %{REQUEST_PROTOCOL}://www.%{HTTP_HOST}/$1 [L,R=301]
# Concrete5 pretty URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
I'm having to work on the live server because the certificate is only valid there (with www. required).
I've tried many variations of the above, but am stumped, so am hoping fresh eyes on this will help, many thanks in advance.
Your 2nd rule isn't looking right as REQUEST_PROTOCOL has value of HTTP/1.1.
You can use this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Force HTTPS for /book unless dev or already there
RewriteCond %{HTTP_HOST} !^dev\.
RewriteCond %{HTTPS} !^on$
RewriteRule ^book https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# Force www prefix unless dev or already there
RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} !^(?:www|dev)\. [NC]
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
# Concrete5 pretty URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
I am trying to keep my main domain structure from being too cluttered so I am parsing all of my domains into their own subfolder. So, what I am trying to do is when a user goes to http://mydomain.com they are actually sent to http://mydomain.com/sub-directory
This bit of code works:
#redirect to submain subdomain
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /submain/
RewriteRule ^submain/(.*) /$1 [L,R=301]
RewriteRule !^submain/ submain%{REQUEST_URI} [L]
However it breaks all the other subdomains I have loaded into my main directory.
Any ideas on how to fix this?
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /submain/
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$
RewriteRule ^submain/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$
RewriteRule !^submain/ submain%{REQUEST_URI} [L]
Create a .htaccess file in root folder, and put this content inside(just change example.com and my_subdir):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>