I run a university club website which has two three (update: I have recently discovered the third) domains, let's say www.meow.co.uk, foo.uni.ac.uk/bar/meow/ and uni.ac.uk/bar/meow. I'm using the following .htaccess in the folder foo.uni.ac.uk/bar/meow/ in order to remove .html from the pages.#meow.co.uk/page will display the contents of meow.com/page.htmlRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME}.html -fRewriteRule ^(.+)$ $1.html [L,QSA]#302 from meow.co.uk/page.html to meow.com/pageRewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/RewriteRule ^(.*)\.html$ /$1 [R=302,L]This works fine on www.meow.co.uk/page.html --> www.meow.co.uk/page but for the other domain, it treats foo.uni.ac.uk/ as the root directory, so foo.uni.ac.uk/bar/meow/page.html --> foo.uni.ac.uk/page. I want it to go to --> foo.uni.ac.uk/bar/meow/page.How can I modify the htaccess file so that it works for both domains? Or failing that how can I redirect from foo.uni.ac.uk/bar/meow to www.meow.co.uk?
.htaccess rewrite when site has multiple domains
domains;htaccess;multiple domains
RewriteRule ^(.*)\.html$ /$1 [R=302,L]The problem is that for www.meow.co.uk you need to redirect to /$1 (as above) and for foo.uni.ac.uk you need to redirect to /bar/meow/$1. I don't think there is an immediate way around that.However, you could conditionally set an environment variable (eg. BASE_URL) to the value of the required base URL for the redirect depending on the value of the Host. And use this environment variable in the RewriteRule directive.For example, at the top of your script, set the environment variable:SetEnvIf Host foo\.uni\.ac\.uk BASE_URL=/bar/meowWhen the site is accessed via www.meow.co.uk then BASE_URL will not be set (ie. it's empty).Then, change your RewriteRule substitution to use this:RewriteRule ^(.*)\.html$ %{ENV:BASE_URL}/$1 [R=302,L]You should change the 302 (temporary) redirect to a 301 (permanent) redirect when you have confirmed it's working OK.UPDATE: However, you are better off canonicalizing the URL and redirecting to the canonical domain (ie. www.meow.co.uk). With three different domains you have a lot of potential duplicate content. So, instead of the above, simply redirect to the canonical domain at the top of your script:RewriteCond %{HTTP_HOST} !=www.meow.co.uk [NC]RewriteRule ^bar/meow/(.*) http://www.meow.co.uk/$1 [R=301,L]Just to clarify... you have already changed the URLs on your site to use the extension-less version and this redirect is only required for old URLs that might have been indexed, shared, etc. Yes?