I have this in my htaccess file:
RewriteCond %{HTTP_HOST} ^my\.domain\-uk\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.my\.domain\-uk\.net$
RewriteRule ^/?$ "http\:\/\/www\.domain\-uk\.net\/my\-integra" [R=301,L]
RewriteCond %{HTTP_HOST} ^status\.domain\-uk\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.status\.domain\-uk\.net$
RewriteRule ^/?$ "http\:\/\/www\.domain\-uk\.net\/service\-status" [R=301,L]
RewriteCond %{HTTP_HOST} ^dd\.domain\-uk\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.dd\.domain\-uk\.net$
RewriteRule ^/?$ "https\:\/\/sub\.domain\.co\.uk\/preauth\/0J9A7MT35N" [R=301,L]
the status. redirects but the two after are showing 500 Internal Server Error
above this i have the standard Wordpress code:
# 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
The first rules that you want in your htaccess file are the ones the redirect the browser, the order is important, you don't want to redirect the browser after wordpress's internal rewriting. So first, you can clean up your redirect rules:
RewriteCond %{HTTP_HOST} ^(www\.)?my\.domain\-uk\.net$ [NC]
RewriteRule ^/?$ http://www.domain-uk.net/my-integra [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?status\.domain\-uk\.net$ [NC]
RewriteRule ^/?$ http://www.domain-uk.net/service-status [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?dd\.domain\-uk\.net$ [NC]
RewriteRule ^/?$ https://sub.domain.co.uk/preauth/0J9A7MT35N [R=301,L]
The ? makes the grouping optional, and the NC ignored the case. So after these rules, you can put your wordpress rules.
Related
I have this code in my .htaccess file which does as the comments say:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
Options -Indexes
# redirect all traffic to correct domain
RewriteCond %{HTTP_HOST} ^itl\.|^(www\.)?(integratelecom|integra|integratelecommunications)\b [NC]
RewriteRule ^ https://www.example.net%{REQUEST_URI} [L,R=301,NE]
# redirect admin./ssladmin. sub domain to the correct folder
RewriteCond %{HTTP_HOST} (admin|ssladmin)\.itl\.uk\.net$ [NC]
RewriteRule !^admin/system/ admin/system%{REQUEST_URI} [L,NC]
# redirect subdomain.X to subdomain.example.net
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.(?!itl\.)[^.]+\. [NC]
RewriteRule ^ https://%1.example.net%{REQUEST_URI} [L,NE,R=302]
# map subdomains to correct folder
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.example\.net$ [NC]
RewriteRule !^subdomains/ subdomains/%1%{REQUEST_URI} [L,NC]
RewriteRule ^(subdomains/|admin/|index\.php$) - [L,NC]
# stop external linking to website but allow listed domains below
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.co.uk [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?itl.uk.net [NC]
#RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.|admin\.|ssladmin\.)?example.net [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]
#######################################
############## MAIN SITE ##############
#######################################
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(blog)/(post|tags|category)/([\w-]+)/?$ index.php?id=$1&type=$2&unique=$3 [QSA,NC,L]
RewriteRule ^(blog)/(archives)/([0-9]{4})/([0-9]{2})?$ index.php?id=$1&type=$2&year=$3&month=$4 [QSA,NC,L]
RewriteRule ^(support/knowledgebase)/(article|category|search)/([\w-]+)?$ index.php?id=$1&type=$2&unique=$3 [QSA,NC,L]
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]
All of the above is working fine, but i need to force every domain and subdomain to use HTTPS, I have tried adding in:
RewriteCond %{HTTPS} off %HTTP_HOST [NC]
RewriteRule ^ https://%1.domain.net%{REQUEST_URI} [L,NE,R=302]
But that keeps returning an Internal Server Error
I also tried these two lines, but that adds %25 to the end of the URL
#RewriteCond %{HTTPS} off
#RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]
To force HTTPs you can use:
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
It basically says, if HTTPs is not equal to ON, then it will force the website to display using SSL.
Make sure you clear your cache before testing this.
I have a strange issue where pages are redirecting to the homepage. Let me explain - my website is thedj.com.au
Now when I type in www.thedj.com.au/payments it redirects to thedj.com.au (even though it should be going to the page https://thedj.com.au/payments).
Any idea why this is and how to fix?
My htaccess file is below:
# BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^home.htm$ https://thedj.com.au/ [R=301,L]
RewriteRule ^photos.htm$ http://photos.thedj.com.au/ [R=301,L]
RewriteRule ^contacts.htm$ https://thedj.com.au/contact-us/ [R=301,L]
RewriteRule ^booking.htm$ https://thedj.com.au/book-dj/ [R=301,L]
RewriteRule ^downloads.htm$ https://thedj.com.au/downloads/ [R=301,L]
RewriteRule ^payonline.htm$ https://thedj.com.au/payments/ [R=301,L]
RewriteRule ^price.htm$ https://thedj.com.au/pricing/ [R=301,L]
RewriteRule ^questions.htm$ https://thedj.com.au/faq/ [R=301,L]
RewriteRule ^links.htm$ https://thedj.com.au/links/ [R=301,L]
RewriteRule ^thankyous/index.htm$ https://thedj.com.au/testimonials/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://thedj.com.au/ [L,R=301]
</IfModule>
# END HTTPS Redirection Plugin
# 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
RewriteCond %{HTTP_HOST} ^mrdj\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mrdj\.net\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mrdj\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mrdj\.com\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^thedjs\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.thedjs\.com\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^theperthweddingdjs\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.theperthweddingdjs\.com$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^thedjs\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.thedjs\.net\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au" [R=301,L]
Note:
I've tried commenting out the lines
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://thedj.com.au/ [L,R=301]
However this has not fixed the issue. I'm thinking this may perhaps be because the website is entirely https:// - but any more ideas would be much appreciated.
Best,
Kosta
The .htaccess shouldn't do any redirect here.
For testing, this website could be useful.
Is this configuration from your live site? Because https://thedj.com.au/payments works for me.
Browsers tend to cache permanent redirects quite aggressively. You need to clear the complete cache or use the private browsing mode to test a redirect again. (But you need to close ALL private browsing windows and then open a new one)
I have the following htaccess file. I do not want to perform a redirect from https to http on a certain file. how can i achieve this?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.spectrumasa.com$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^intranet.spectrumasa.com$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/ [R=302,L]
RewriteCond %{HTTP_HOST} ^www.asb.com.au$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.spectrum-geopex\.com\.eg$ [NC]
RewriteRule ^(.*)$ http://www.spectrumgeo.com/spectrum-geopex [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I would like to access only the following through https http://www.spectrumgeo.com/wp-content/uploads/Spectrum_logo_email-171w.jpg
Add a condition to your rule:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/wp-content/uploads/Spectrum_logo_email-171w\.jpg$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
You can have something complex in picking with to redirect to https:// from http:// but you can accomplish a simple redirect on a single file via this method.
RewriteEngine
Redirect http://www.spectrumgeo.com/wp-content/uploads/Spectrum_logo_email-171w.jpg https://www.spectrumgeo.com/wp-content/uploads/Spectrum_logo_email-171w.jpg
This will solve accessing only the above url you have through https://
I've tried several solutions posted here, none of them seem to work - I just get redirect errors.
What I am trying to do is redirect all traffic to https for:
http://domain.com
http://www.domain.com
https://domain.com
http://alias.com
http://www.alias.com
https://alias.com
should all go to: https: // www.domain.com
currently addresses starting like: http: // www won't redirect to https.
here is the htaccess file
RewriteEngine On
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
You should get rid of the www redirects at the bottom:
RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
Don't need them, you just need a single redirect at the top, replace:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
with
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
This should take care of all the redirects.
The following code in the .htaccess file is supposed to, among others I guess, redirect the secondary domains towards the main domain:
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^secondaryDomain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain1.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain2.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain3.com$ [OR]
RewriteCond %{HTTP_HOST} ^secondaryDomain3.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain4.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain4.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain5.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain5.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain6.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain6.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^secondaryDomain7.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.secondaryDomain7.com$
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
Unfortunately if I type www.secondaryDomain.com/index.html or www.secondaryDomain.com/directory it is not redirected towards the main domain.
What has been done wrong in the .htacess file?
RewriteRule ^/?$ "http\:\/\/mainDomain\.com\/" [R=301,L]
This rewrites only URLs ending in / or nothing at all. You should use something like:
RewriteRule (.*) "http\:\/\/mainDomain\.com$1" [R=301,L,QSA]
Which redirects and preserves all path-info.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ http://mainDomain.com/ [L]
</IfModule>
I am assuming that this .htaccess file is for secondarydomain.com ...