I want rewrite my subpage to subdomain in Apache server. Something like this:
www.example.com/mycats/news
to
www.news.example.com
I found this code but not work:
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).example.com$ [NC]
And what is need except the code? Apache and wildcard mod?
Thanks for any help
Try
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^mycats/(.+)/? http://www.$1.example.com/ [L,R]
If you don't want to externally redirect the browser, remove the R
Related
I am trying to handle wildcard subdomains with url masking in apache.
Correct rewrite rules should achieve the following:
http://demo.system.dev to to http://system.dev?subdomain=demo
http://sample.system.dev/user/edit/100 to to http://system.dev/user/edit/100?subdomain=sample
http://debug.system.dev/project/edit/new to to http://system.dev/project/edit/new?subdomain=debug
So far i have the following rule in my .htaccess
RewriteCond %{HTTP_HOST} ^(.*)\.system\.dev
RewriteRule ^(.*?)$ http://system.dev%{REQUEST_URI}?subdomain=%1 [L]
which looks like its working ok except that the browser url is also changed. I would like the browser url to remain the same and internally route the request but i am not sure how to achieve this.
Try this rule in your root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !(?:^|&)subdomain= [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.system\.dev$ [NC]
RewriteRule (.*) $0?subdomain=%1 [L,QSA]
You can not internally rewrite to another domain. So when you go to your subdomain it will redirect to main domain as you have it. So you will need to use relative URL and see if that works for you.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www\.)?system\.dev [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.system\.dev [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}?subdomain=%1 [L]
I have an apache server hosting a site. I have 2 domains pointing to this server, www.mysite.se and www.mysite.com.
I'm trying to figure out how to in the htaccess file to redirect traffic coming from the www.mysite.se domain to www.mysite.com/se/
I've tried several ways but cannot get it to work. I always just end up on the root of the site, as in www.mysite.com instead of the /se/ path.
This is what I've tried so far:
RewriteEngine On
RewriteCond %{http_host} ^www\.mysite\.se [NC]
RewriteRule ^(.*)$ http://www.mysite.com/se/ [R=301,NC]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite.se$ [NC]
RewriteRule ^(.*)$ /se/$1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite.se$
RewriteRule ^(/)?$ se [L]
What am I doing wrong?
This seems to have finally done it!
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite.se$
RewriteRule (.*)$ http://www.mysite.com/se/ [R=301,L]
i don't even know whether this is possible or not.
i've 3 domain names:
mytest.com
test88.com
test99.com
mytest.com is the main domain where all the content is located. in my case it is wordpress which is installed on that webspace.
my htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)test88.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test88 [R,L]
RewriteCond %{HTTP_HOST} ^(.*)test99.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test99 [R,L]
i want to keep the domainname in case a visitor goes to test88.com but i also want to keep the rest of the path. It should look like this in the address-bar:
http://www.test.88.com/wp/?page_id=10&test=test88
ist this possible?
thanks in advance
Do you want the content from mytest.com show up under the test88.com and test99.com, basically creating duplicates ?
In that case you probably don't want to mod_rewrite to redirect [R], but to reverse-proxy [PT] the content from the main domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)test88.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test88 [PT,L]
RewriteCond %{HTTP_HOST} ^(.*)test99.com [nc]
RewriteRule ^(.*)$ http://%1mytest.com/wp/?page_id=10&test=test99 [PT,L]
Make sure mod_proxy is installed on your Apache.
We have a .htaccess-file like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mysite\.no [NC]
RewriteRule (.*) http://www.mysite.no/$1 [R=301,L]
Which autoappend www in front of the URL if it's missing. In addition we have to expand our site to a mobile version that we'd like to call m.mysite.no.
How do you do this and make the mod_rewrite ignore the www-rule? Unfortunately, this site is live, so we can't do much testing and we have little experience on the field.
Change:
RewriteCond %{HTTP_HOST} !^www\.mysite\.no [NC]
To:
RewriteCond %{HTTP_HOST} !^(www|m)\.mysite\.no [NC]
I have a client folder located at http://www.example.com/client
However, I've now installed SSL on the server, and want to add a permanent redirect using HTACCESS so that whenever /client is accessed, that it redirects to: https://www.example.com/client
Anybody know how to do that?
I've redirected my domains in the past like this:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
This should not affect the solution, but the site must still redirect to www.example.com FIRST, and then to https://www.example.com/client if for example, http://www.example.co.za/client is entered.
Try this:
RewriteCond %{HTTPS} !on
RewriteRule ^client(/.*)?$ https://www.example.com%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteRule ^/?$ https://www.example.com/client [301,NC,L]
It tells the apache, whenever the url is https://www.example.com or either with slash at the end, will redirect to ur /client