htaccess retwrite subfolder to the maindomain - .htaccess

my domain name is www.hangings.com.au where as the project is hosted inside the folder named hangings so I need to enter something as www.hangings.com.au/hangings
Can anyone tell me how can I rewrite htaccess file so that it will show the content hosted in www.hangings.com.au/hangings when someone enters as www.hangings.com.au in their browser.
I tried something like the below
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.hangings.com.au/$1 [NC]
RewriteRule ^(.*)$ www.hangings.com.au/hangings$ [L,R=301]
but I am getting a browser error "This Website has a Redirection Loop"

The redirect loop is because of www.hangings.com.au/hangings matches also the condition.
If it's enough for you, that calls to www.hangings.com.au/ are redirected to the subfolder, an nor deeper structure, the following should be enough.
RewriteEngine on
RewriteRule ^/$ /hangings [R]

Related

301 Redirect including Subdomain and Folder

I have two domains:
subdomain.domain.tld
subdomain.domain.tld2
They both are linking to the same ROOT Folder, lets call it "start".
So if I enter one of the both urls, It will open the index file in "start".
Now I have a subfolder in this "start" folder, lets call it "subfolder".
I can open this subfolder by entering
subdomain.domain.tld/subfolder/ OR
subdomain.domain.tld2/subfolder/
I wish that if someone calls
subdomain.domain.tld/subfolder/
it will 301 to
subdomain.domain.tld2/subfolder/
Also, if someone would call
subdomain.domain.tld/subfolder/subxyz/page=123
it will 301 to
subdomain.domain.tld2/subfolder/subxyz/page=123
I created a .htaccess in the "subfolder" with the following code, but its not working. I tried also a bunch of other Redirect Codes that I found here on Stackoverflow, but none is working for me so far. Any hel is welcome!
RewriteCond %{HTTP_HOST} ^http://subdomain.domain.tld/subfolder/[NC]
RewriteRule ^(.*)$ http://subdomain.domain.tld2/subfolder/[L,R=301,NC]
You can use :
RewriteEngine on
#--If http_host is "subdomain.domain.tld"--#
RewriteCond %{HTTP_HOST} ^subdomain.domain.tld$
#-- And the uri is /subfolder/--#
RewriteCond %{REQUEST_URI} ^/subfolder
#--Then, redirect the uri to another host --#
RewriteRule ^(.+)$ http://subdomain.domain.tld2/$1 [QSA,L,R=301]

.htaccess redirect folder to subdomain

I've tried applying a few of the answers found on stackoverflow, but either I'm missing something or I'm plain dumb.
Basically I got a main domain name. This domain already has a non-www redirect. So http://domain.com becomes http://www.domain.com. This domain also has a mobile version found inside the the 'm' folder. So accessing the domain name like http://www.domain.com/m/ works and so does http://m.domain.com. What I'm trying to achieve is simple: anyone whom goes to the site via http://www.domain.com/m/, or http://www.domain.com/m/about should be redirected to the subdomain version so to http://m.domain.com or http://m.domain.com/about in the second case listed above.
Whatever I tried implementing ended up with errors, either I managed to disable direct access to m.domain.com, but it worked via domain.com/m/, or redirect loops.
Thanks!
You can use this code in your DOCUMENT_ROOT/.htaccess file of domain.com main .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^m/(.*)$ http://m.%1/$1 [L,NC,R=302]
# non-www to www
RewriteCond %{HTTP_HOST} !^(m|www)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,NC,R=302]

Hiding Directory in URL with htaccess is not working

I have website1.com setup so that when users visit website1.com they get redirected via a meta tag in an index.html to website1.com/directory
Then they use the website and go to links such as website1.com/directory/index.html or what ever. I am trying to hide the "directory" in the link so that users only see website1.com/index.html
I have place the htaccess which is to rewrite the url to website1.com/index.html at website1.com/directory/.htaccess
I am not doing anything else special and this should be an easy task. My current exact htaccess is as follows:
RewriteEngine On
RewriteCondition %{REQUEST_URI} !^directory/
RewriteRule ^(.*)$ directory/$1 [L]
Should be easy right..... All I get is a 404
In my server I have Mod_Rewrite & mod security and suspect one of them is causing this not to work but can't imagine why. Am I missing something here?
Your rule is incorrect since %{REQUEST_URI} variable has starting /
You need to place this in document root
Use this code in document root .htaccess:
RewriteEngine On
RewriteCondition %{REQUEST_URI} !^/directory/
RewriteRule ^(.*)$ /directory/$1 [L]

.htaccess forward from one domain to a specific .html page

I know how to use .htaccess to forward everything in one domain to a new domain name. But in this case, I want everything from one domain to go to a specific .html page on a different domain. That's where I'm lost. I'm trying the following but it just redirects to a folder and the page in question is in that folder but obviously, I don't want people seeing the contents of that folder. Make any sense? So example.com needs to go to yyy.com/some-page.html
This is what I'm currently using:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule ^(.*)$ http://www.1.yyy.com/$1 [R=301,L]
Try:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (www\.)?5\.xxxx\.com [NC]
RewriteRule .* http://www.1.yyy.com/some-page.html [R,L]
You can also put a blank index.html page to the directory in question to mask its contents or
you can put index.php file with this code <? header ("location: http://www.1.yyy.com/some-page.html"); ?> that will redirect a user to the desired page.
$1 is a place holder for the 1st pattern match. So if you are rewriting domaina.com/someurl/, it is attempting to load domainb.com/someurl/. Swap the $1 with the actual page --- e.g. somepage.html and it should work. But unless both of these domains are pointing to the same files/directories, the rule seems a bit overcomplicated.
So how about just a simple redirect?
Try this in your .htaccess file.
redirect 301 / http://somesite.com/somepage.html
OR you can try this.
RewriteRule ^(.*)$ http://somesite.com/somepage.html [R=301,L]
It does work and you can test my RewriteRule below.
http://htaccess.madewithlove.be/
There must be something else going on.

htaccess redirect if filename equals something

I'd like to set a redirect (preferably with RewriteCond) so that if the requested file is index.php regardless of directory, it will be redirected to another site.
So visiting /index.php or/files/index.php or /stuff/index.php (etc.) will all redirect you to another domain.
Here is a general way to do it. This rule set should be placed in the .htaccess file in the root directory:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} index\.php/? [NC]
RewriteRule .* http://otherdomain.com/ [R=301,L]
Redirects permanently any URL that holds index.php in any position, like
http://mydomain.com/index.php or
http://mydomain.com/any/folder/quantity/index.php or
http://mydomain.com/any/folder/quantity/index.php/any/folder/quantity/
To
http://otherdomain.com/
That's it. You don't explain much so nothing is passed to the other domain, just as you say in your question:
...redirected to another site.
These rules should do it (when placed inside /.htaccess file):
RewriteEngine On
RewriteRule (?:^|/)index\.php$ http://otherdomain.com/ [R=301,L]

Resources