I am trying to set up an .HTACCESS so I can have multiple domains with the same root directory. I want the htaccess to redirect to a php file dependant on domain name. I don't want to have to set it up per domain - I want it to be for any domain that I set up with the common root directory to redirect to its own php of the same name. eg
mydom1.co.uk will direct to mydom1.php ,
another.co.uk will direct to another.php
thanks in advance for any help
You can put the following in your .htaccess file at the document root:
RewriteEngine On
RewriteBase /
RewriteRule .* %{HTTP_HOST}.php [L,QSA]
However, I expect you'll need to amend the main rule to handle the request of different pages. At the moment everything will be rewritten to /domain.php
Related
I am attempting to redirect a subfolder on an apache2 server to the root of an entirely different domain, without including the path of the folder in the new domain.
So, in mysite.com/folder-1/folder-2 I have a .htaccess file like so:
RedirectMatch 301 / http://a-totally-different-site.com/
This sort of works, but includes the path in the redirect. So, when you visit mysite.com/folder-1/folder-2 it goes to a-totally-different-site.com/folder-1/folder-2
What I wish to happen, is for the subfolder to redirect to the root, so visiting mysite.com/folder-1/folder-2 will go to a-totally-different-site.com
Is this possible with .htaccess? I have tried a few different approaches I found, but none are working.
Simple rewrite rule should do:
RewriteEngine On
RewriteRule ^ http://a-totally-different-site.com [R=301]
I want to redirect a path: /folder/filename.html to: /folder/newfolder.
My host says I must create a dummy file at /folder/filename.html or it won't redirect. I can't do this as by creating the /folder, that messes up Joomla which would normally create that part of the path dynamically. I'm not sure I believe my host, surely it's possible to redirect a path regardless whether there is a file there?
In your .htaccess after RewriteEngine On just add this line
RewriteRule ^/folder/filename.html /folder/newfolder/filename.html [R=301,L]
I'm having difficulties getting an htaccess to work with a subdomain.
my server structure:
root / index.php ---//codeigniter index file, for application A, main domain points here.
root/staging/StagingWebsite ---// my subdomain is pointing here.
the folder StagingWebsite has a file called temp.html
moving on, my root htaccess file is this :
RewriteEngine on
RewriteCond
RewriteCond $1 ^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Which turns any access to MyDomain/foo to MyDomain/index.php/foo. (without showing the index.php).
The problem:
When I try to access my subdomain/temp.html, I get a 500 internal error.
when I remove my root/.htaccess, it works fine. So it's obviously my htaccess file.
I've figured out the problem is that the root/.htaccess rule is being applied to the subdomain, which breaks everything, But I have no ideahow to sort it out.
I've placed an empty .htaccess file inside the root/staging/StagingWebsite hoping it would just over-write any previous htaccess settings, But that didn't work.
EDIT
I fixed the issue specifically but I don't like the solution.
I added a RewriteCond to only run the rewrite rule for as specific domain.
Is there a way to solve this without specifying a domain?
Create /root/staging/StagingWebsite/.htaccess with this line only:
RewriteEngine on
This will overwrite any parent's rewrite rules.
I have several domain names that point to the same IP address. I currently redirect them from the /default.asp file to the appropriate folder based on the SERVER_NAME. For example:
http://domain1.com redirects to http://domain1.com/folder1
http://domain2.com redirects to http://domain1.com/folder2
This works, but the urls display the folder name in the browser:
http://domain1.com/folder1/somepage.htm
And the user can't go to a page without entering the folder name:
http://domain1.com/somepage.htm // This fails because it isn't in the root folder.
Can I use the .htaccess file to (1) route page requests to the appropriate folder and (2) prevent the folder name from appearing in the browser?
That'd also move the redirection from the /default.asp file to the .htaccess file where it probably belongs.
Thanks!
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteCond %{lowercase:%{HTTP_HOST}} ^www\.([^.]+)\.example\.com$
RewriteRule ^(.*) /home/%1/www$1
I have a hosting account which provides me a folder to publish my files for my domain (say www.example.com). I have set up Drupal for www.example.com with .htaccess at the top folder to enable clean-urls for the Drupal installation. Now I want to have a Wordpress installation under www.example.com/blog/ and have clean URLs for that blog. But while using .htaccess it is not working ok as the .htaccess at the top folder will override the sub-folder one. How to achieve what I intend to?
This really depends on the exact content of your respective .htaccess files.
One workaround is to add a RewriteCond to the head of the main .htaccess file that, if the request URI matches the sub-directory, stops parsing:
RewriteCond %{REQUEST_URI} ^/blog
RewriteRule .* - [L]
this should lead to the blog URLs being parsed properly, based on the rules specified there.