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 ...
Related
AddDefaultCharset UTF-8
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
RewriteRule ^(.*)/$ ./msadmin/index.php?string=$1 [NC,L]
after writeing https://example.com/msadmin/ redirecting to
https://example.com/msadmin/index.php?string=https://example.com/msadmin
which part is wrong?
I need to go to https://example.com/msadmin/
Thanks
Replace all of your code with this:
AddDefaultCharset UTF-8
RewriteEngine On
RewriteBase /
## add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/?$ msadmin/index.php?string=$1 [QSA,L]
Make sure to test it in a new browser.
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.
Currently my site can only be visited when visiting www.mysite.net or http://www.mysite.net. How can I change this so that when one just visits http://mysite.net, that you will be directed to www.mysite.net?
Here is my current HTACCESS file content
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I also tried this...
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %mysite.net !^www\.
RewriteRule (.*)$ http://www.%mysite.net/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thank You
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
edit:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
edit 2
Add URL Rewrite Rule To Wordpress this is not helpful?
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]
This is my current script... I need to allow "sub.domain.com/register/USER"
Currently, I have a rerwrite cond for "sub.domain.com" which points right to "sub.domain.com/login"
What am I doing wrong?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteCond %{HTTP_HOST} ^(.+).domain.com$
RewriteRule ^register(.*) https://%1.domain.com/register$1 [L,R=302,QSA]
RewriteCond %{HTTP_HOST} ^(.+).domain.com$
RewriteRule ^$ https://%1.domain.com/login/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
As of update, I have a redirect loop in /register/USER..
Replace your first set of rules with this:
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteCond %{HTTP_HOST} ^(.+).domain.com$
RewriteRule ^register(.*) - [L,R=302,QSA]
EDIT: Maybe a better solution is to rewrite only if the URI isn't /register/user. So get rid of the above rule, and change the one below it to:
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteCond %{HTTP_HOST} ^(.+).domain.com$
RewriteCond %{REQUEST_URI} !^/register/?.*
RewriteRule ^(.*)$ https://%1.domain.com/login/ [L,R=302]
I am trying to add a "/login" to wildcard subdomains.
For example:
*.example.com would be redirected to *.example.com/login
but, i want certain subdomains not to be redirected, such as...
help.example.com, m.example.com, etc.
What is the best way to do this, and would this be done in .htaccess or in httpd.conf?
Thank you for your help.
Updated below:
Here is what I currently have:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m.example.com$
RewriteCond %{HTTP_HOST} ^(.+).example.com$ [NC]
RewriteRule ^/$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You were almost there
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m\.example\.com$
RewriteCond %{HTTP_HOST} !^help\.example\.com$
RewriteCond %{HTTP_HOST} ^(.+\.example\.com)$ [NC]
RewriteRule ^/?$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>