htaccess RewriteCond help for new development site - apache

I have having a real problem here and I am hoping someone can help me out - let me explain:
I have a site - domain.co.uk - for the past 6 months this site has been sat on holding pages so google gets to know the domain.
I also have domain.com and domain.org - these were also set up at the same time.
We have a new website under development using a Drupal multisite install where all of the multisites are sub-domains.
Here is my problem!! The new website is now under development and I need to add various rules to the htaccess to redirect back to the holding pages but these rules are new to me and I dont really have a clue what I am doing!
This is what I need to do:
The primary domain is domain.co.uk.
I need to redirect all users requesting domain.co.uk to domain.co.uk/holding/index.php,
but I need to put an IP address exclusion in for us and the developers for testing the new site so we can see what is going on with the new website.
The website also has .com alias and this needs to go to domain.co.uk for all requests.
So here is what I have so far and it does not work as it should:
// I set this to re-write anything except the subdomains I want to see
RewriteCond %{HTTP_HOST} !^(www.domain\.co\.uk)|(subdomain1.domain\.co\.uk)|(subdomain2.domain\.co\.uk)|(subdomain3.domain\.co\.uk)$ [NC]
RewriteRule (.*)$ http://www\.domain\.co\.uk%{REQUEST_URI} [R=302,L]
// then I have put in some rules for checking the ip's and producing a redirect that does not match earlier requests.
RewriteCond %{REMOTE_HOST} !^(xx\.xxx\.xxx\.xx)|(xx\.xx\.xx\.xx)$
RewriteCond %{REQUEST_URI} !/holding/index\.php$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css) [NC]
RewriteRule ^(.*)$ /holding/index\.php [R=302,L]
The result so far is:
if a general user goes to the domain.co.uk it redirects to the holding page - GOOD
if a user from the 'excluded ip's address list goes to domain.co.uk they also get redirected - BAD - but if they go to .domain.co.uk/index.php the Drupal site loads with the new design.
If a user from the excluded ip's list goes to subdomain1.domain.co.uk they get redirected to the holding pages - BAD- this, I think, should not happen due to the 1st rule but I am totally lost.
Anyone got any ideas how to get this working so that a user with an allowed ip can access the new website and all it's subdomains but any general user is directed to the holding pages.
Many thanks - my head is about to explode!!

${REMOTE_ADDR} is the IP Address, ${REMOTE_HOST} is the hostname if available.
You could also temporarily add ${REMOTE_ADDR} into the redirect to the holding page to check that you are putting the right addresses in, e.g.:
RewriteRule ^(.*)$ /holding/index\.php?ip=${REMOTE_ADDR} [R=302,L]

Related

Redirect all pages to subdomain while keeping the content

I want to redirect all my pages and video content to my sub domain (where I have my CDN)
currently I have link in a videogame, with people who generate traffic and I have a lot of link already in the game that I cant change since it will take forever, so I want redirect all people that will click on the link to my sub domain, where I have my CDN setup
https://exemple.com/folder/contents/video.mp4 TO https://cdn.exemple.com/folder/contents/video.mp4
I already try few rewrite command with htaccess but I get the error TOO_MANY_REDIRECT and I don't know what to do
This should work for you:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.+\.mp4)$ https://cdn.exemple.com/$1 [R,L]
Put this at the top of your /root/.htaccess before other rules and make sure to Clear your browser cache before testing this new redirect.

Canonicalizing domain name with mod_rewrite

I had a working .htaccess for my website, but I decided to add domain name canonicalization - e.g. prepend 'www' if it is omitted.
Here's what I'm using now:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule ^.*$ http://www.domain.com/$0 [L,R=301]
RewriteRule ^$ http://www.domain.com/blog/ [L,R=301]
// etc
The first condition/rule are the ones I added. The second rule redirects empty filepath to "blog/". Now, the problem is, if I type in a path like "domain.com/page", for some reason it redirects me to the blog. If I change the first rule to http://www.domain.com/test?url=$0, it correctly redirects me to www.domain.com/test?url=page. What am I doing wrong, and is there a way to possibly see some sort of logs/debug output? (I'm using shared hosting so I don't have access to low level logs)
Update: its working fine now; it seems the redirects were cached somewhere, even though clearing all browser data didn't help. Could it be possible that the redirects got cached on proxy level, and how to deal with it, since it makes editing/debugging .htaccess nearly impossible?

htaccess redirect for global subdomains system - all subdomains redirected to one php file to handle them all

i really could use some advices related to subdomains.
recently we decide to make every subdomain of main portal to be available for blogs (something similar to lets say any blog platform)
so what i cant achieve is to make redirection to certain folder of main portal site or php file like:
xxxxx.domain.com/index.php?get=xx&get2=xx -> to be run by actual php file located on main portal account, lets say subdomains.php?get=x&get2=xx, alternatively - to be run by mainportal/subdomains/index.php?get=x&get2=xx
i tried with
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.pl$ [NC]
RewriteRule (.*) subdomain.php [L]
effect was almost correct but get parameters are missing:(
on the other hand it can be entirely wrong... i simply dont understand or that rewrite rules:(
thanks for any help/tips
You can try with QSA (query string append):
RewriteCond %{HTTP_HOST} ^.*\.domain\.pl$ [NC]
RewriteRule . subdomain.php [QSA]

Can I use htaccess to invisibly redirect one domain to a subdomain on another domain?

I've been pulling my hair out trying to research this and find out if this is possible. Any help would be appreciated.
I have two domains. Let's call them foo.com and bar.com. I only have one web server, so right now, they're pointing to the same place.
I have a separate site set up at bar.foo.com.
I want all visits to bar.com to go to bar.foo.com, but still say "bar.com" in the browser's address bar.
Here's what I've got in my htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bar.com$ [NC]
RewriteRule ^(.*)$ http://foo.bar.com/$1 [R=301,L]
This successfully redirects it, but, you end up seeing "foo.bar.com" in the address bar.
Using htaccess, can I get this redirect to happen "invisibly", so that if the user types in "bar.com", they will still see "bar.com" in the browser?
I don't have access to the apache config files on the server, so I'm limited to what I can put in a htaccess file.
Any help or advice would be much appreciated.
Thanks!

Apache Rewrite/Redirect different for TLD vs directory

I've migrated the content of a site from one domain to another. I have .htaccess Rewrite set up successfully to redirect any request to the old domain to the same location on the new domain, which is working fine, using the following code:
RewriteEngine On
rewritecond %{http_host} ^roundeltable.com
rewriteRule ^(.*) http://wheelspin.tv/$1 [R=301,L]
However, I want to go a little further. When somebody simply requests the old TLD (http://roundeltable.com/) I want them to be redirected to a specific page within the new domain (http://wheelspin.tv/rt). If they make a request to any other location from the old domain (for example, http://roundeltable.com/about) I want them to be sent to that exact same place at the new domain (http://wheelspin.tv/about) the way they currently are now.
Is this possible? If so, how?
So I've found the solution to this issue, which ended up being provided by somebody from Media Temple's service department. Here's the entire code required in the .htaccess file to make this work:
RewriteEngine On
RewriteRule ^$ http://wheelspin.tv/rt/ [L]
RewriteRule ^(.*)$ http://wheelspin.tv/$1
Obviously substitute whatever domain you want to redirect to in place of mine, but that's the solution for my example. Thanks for the help!
If you want to see all the details on my solution, I have it here: christiaanconover.com/media-temple-service-rocks/