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]
Related
i wanted to change the url for my subdirectory from "subdomain1.main.com/subdirectory" to "subdomain2.subdomain1.domain.com"
i tried the htaccess code below but it doesnt work. can someone please help?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain1\.domain\.com$ [NC]
RewriteRule ^subdirectory/(.*)$ http://subdomain2.subdomain1.domain.com/$1 [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain2.\subdomain1\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule !subdirectory%{REQUEST_URI} [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Try this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain1\.domain\.com$
RewriteRule ^subdirectory/(.*)$ http://subdomain2.subdomain1.domain.com/$1 [L,QSA,R=301]
RewriteCond %{HTTP_HOST} ^subdomain2\.subdomain1\.domain\.com$
RewriteCond %{REQUEST_URI} !^subdirectory/
RewriteRule ^(.*)$ /subdirectory/$1 [L,QSA]
I'm using CodeIgniter.
in httacess file, I wrote this code to remove index.php from url:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Now I want to redirect site root to subdomain, with this code:
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ sub.domain.com/$1 [r=301,nc]
domain.com redirected to sub.domain.com successfully. but domain.com/dir to sub.domain.com/dir not work and still opening domain.com/dir.
When I removed first code, redirection worked perfect, but I need to remove index.php too.
Adding $to the end of rewritecond %{http_host} ^domain.com [nc] should fix it for you.
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ sub.domain.com/$1 [r=301,nc]
Would become
rewritecond %{http_host} ^domain.com$ [nc]
rewriterule ^(.*)$ sub.domain.com/$1 [r=301,nc]
Have your rules like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
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>
My current htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2&subid=$3
I've edited the htaccess file. It should only use this htaccess for the main domain and not for subdomains, however subdomains still use this htaccess.
Anyone with more experience than me could point me out in the right direction? Thanks in advance.
Edit:
Here is my current (and working) htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?page=$1&subsectie=$2&subid=$3
Try this:
RewriteEngine On
# first, remove redirect to www by default if no subdomain
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [NC,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&subsectie=$2 [NC,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&subsectie=$2&subid=$3 [NC,L]
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 ...