I would like to rewrite requests to a subdomain to a sub-folder on the site in question.
The subdomain is dev.my-domain.co.za (yes, it has a hyphen in it)
The folder it needs to internally reference is my-domain.co.za/dev.my-domain.co.za
I don't want it to redirect, but to rewrite, so that the user just sees http://dev.my-domain.co.za/...
I found various examples here on StackOverflow, but I was unable to get them to work in my scenario. So I figure it's best I ask and explain my exact situation.
There is going to be a Wordpress site in the sub-folder. I am assuming it is okay to call it via a sub-domain (if you happen to know, please advise). Otherwise, if there are issues, I can ask that question separately in a WP related forum.
So far I tried this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^dev\.domesticflights\-southafrica\.co\.za.*$
RewriteRule (.*) dev\.domesticflights\-southafrica\.co\.za/$1 [L]
Which is my attempt to apply this (from here) to my scenario
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?[^.]+\.example\.com.*$
RewriteRule (.*) myfolder/$1 [L]
I tried adapting many other examples, but none work in my scenario.
You can try these rules to internally redirect from
dev.my-domain.co.za to my-domain.co.za/dev.my-domain.co.za
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?!www)(.+)\.(my-domain\.co\.za)$
RewriteRule ^ http://%2/%1.%2 [P]
Related
I want the root of my website (www.bitumephotofest.it) to redirect to a subdomain (2016.bitumephotofest.it) (I am running a Wordpress multisite). It works.
But I have another subdomain (2015.bitumephotofest.it) and it also redirects to 2016.bitumephotofest.it.
I want the redirect to work only between www.bitumephotofest.it and 2016.bitumephotofest.it. 2015.bitumephotofest.it should be independent as it is a different website.
I tried to look for questions by people with a similar situation but there is always something different and, anyway, those solutions does not work for me.
Here is my code:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} 2016.bitumephotofest.it
RewriteCond %{REQUEST_URI} !wordpress/
RewriteRule ^(.*)$ /wordpress/$1 [L]
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteRule !^(2016) http://2016.bitumephotofest.it [L,R]
Does anyone know what I am missing?
Thank you in advance!
If you want the domain 2015.bitumephotofest.it stay unmodified, you can sort of exit the rewrite rule chain with
RewriteCond %{HTTP_HOST} ^2015\.bitumephotofest\.it$
RewriteRule ^ - [L]
- as the target means don't rewrite, see RewriteRule
- (dash)
A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.
I have the following .htaccess code that successfully rewrites subdomain directories. So if a user visits jim.domain.com they get served placeholder.php?page_type=profile. However, this also affects the main directory http://domain.com. I'd like it so that anything with a subdomain is directed to the placeholder.php page, but using the main directory with no subdomain would act as usual, going to the index.php in the main directory. How would I achieve this? Thanks for any advice.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^exclude.domain.(.*)
RewriteCond %{HTTP_HOST} !^www.domain.(.*)
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule ^$ placeholder.php?page_type=profile [L,QSA]
If your wanting all requests for test.domain.com to go to domain.com/placeholder.php?page_type=profile as in your comment then you need to include the domain in the rewrite
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^exclude.domain.(.*)
RewriteCond %{HTTP_HOST} !^www.domain.(.*)
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule ^$ http://domain.com/placeholder.php?page_type=profile [L,QSA]
this will not how ever deal with this part
but using the main directory with no subdomain would act as usual, going to the index.php in the main directory
because you have no file/directory miss rules that redirect to index.php. Do you need those, or really just want to solve the first part?
I also wonder if your wanting profile replaced with the subdomain match, in which case you want
RewriteRule ^$ http://domain.com/placeholder.php?page_type=%1[L,QSA]
but both of these examples will not rewrite any path of test.domain.com/longer_url because the ^$ is only matching an empty URL path. But how you want to handling paths needs to be decided before a suitable Reerite can be proposed.
This won't work, I don't know why...
# let's say I'm in HTACCESS of domain www.aaa.com
RewriteRule subfolder/script\.php\?param=value¶m2=value2 http://www.bbb.ccom/otherscript.php?otherparam=othervalue [QSA,L]
# domain bbb.com is mine, BUT not on the same account (but same server)
It's not causing any bug or loop, it simply plain not work.
Other instructions in the HTACCESS does work (rewriterules among them) so I know the RewriteEngine is on and works.
It simply won't work because RewriteRule doesn't match QUERY_STRING. You will RewriteCond for that. Use code like below:
RewriteCond %{QUERY_STRING} param=value¶m2=value2 [NC]
RewriteRule ^subfolder/script\.php$ http://www.bbb.ccom/otherscript.php?otherparam=othervalue [QSA,L,R]
I have a little problem in hands.
I am setting up a domain that as 3 languages, example.com for principal domain, en.(...) for english and de.(...) for germany.
Usually I only redirect the httpdocs from the subdomains to the main with ln -S because all languages executes the same code, the difference is matched from php and mysql.
My new host don't provide any ssh connection so I have to use a different approach on this.
It was told to me that it can be done by .htaccess but I already tried a lot of things but only can redirect, changing the url and that's not possible, it have to keep the same, the contents yes, will be from another domain. Can someone help?
This code should looks like the one you're searching for :
www.domain.en .htaccess
RewriteBase /
RewriteRule ^(.*)$ http://www.domain.com/en/$1 [L,R=301]
www.domain.de .htaccess
RewriteBase /
RewriteRule ^(.*)$ http://www.domain.com/de/$1 [L,R=301]
You'll propably adapt the http://www.domain.com/lang/$1 part to your needs.
EDIT
Following your comment, this is a code for subdomains redirections :
domain.com .htaccess
RewriteCond %{HTTP_HOST} ^en\.domain\.com [NC]
RewriteRule (.*) http://domain.com/en/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^de\.domain\.com [NC]
RewriteRule (.*) http://domain.com/de/$1 [QSA,L]
I have multiple domains on my server. I want to redirect all of them to one (example.net).
My .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]
I’m redirecting all URLs on my server to one main domain, but that domain is also redirecting to itself. So www.example.net returns 301 Moved Permanently and redirects back to itself. I’m told that this isn’t good for SEO. How could I fix this?
You need to add a Rewritecond to prevent it from redirecting when you’re already on the domain that you want. There are loads of examples online if you google it, or see the RewriteCond section of Apache’s mod_rewrite documentation.
What you’re looking for is something like:
RewriteEngine on
Rewritecond %{HTTP_HOST} !^www\.example\.net
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]
Just small note:
Thanks goes to TRiG, but I had to remove one slash to make it work correctly (coz it added two slashes after domain name). This works for me:
RewriteEngine on
Rewritecond %{HTTP_HOST} !^www\.example\.net
RewriteRule ^(.*)$ http://www.example.net$1 [R=301,L]