We recently moved a number of static websites from multiple (regional) domains onto a single .com domain which uses Joomla! to serve up content. The new site uses subdirectories and allows uses to navigate between countries. Like this:
newdomain.com/country-name1
newdomain.com/country-name2
newdomain.com/country-name3
We would now like each site to go back to having it’s own domain, but to essentially serve up the same website the user would be seeing by viewing the sub directory (we’ll probably drop the ability to navigate between countries, back that’s largely irrelevant to this post).
How can we do this with as little work as possible to the templates whilst retaining a single Joomla! instance? Has anyone got any experience of similar? I've read some articles but am not sure any of them give the user a true sense of being on a separate domain. I could of course be wrong (tbh, this is a little out of my field of expertise). Spoon-feeding appreciated. :)
You could try mapping the requests to the relevant folders
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com [NC]
RewriteRule ^/(.*) /country-name1/$1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.fr [NC]
RewriteRule ^/(.*) /country-name2/$1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.de [NC]
RewriteRule ^/(.*) /country-name3/$1 [L]
That should map a request for
newdomain.com/country-name1/somepage to newdomain.com/somepage
newdomain.com/country-name2/page to newdomain.fr/page
etc
Obviously you'd also have to make all domain names resolve to the same folder.
Related
I must admit, mod_rewrites are still a bit of black magic for me and I try to stay well away from them unless I really, really need to us them, now I do!
I've just migrated my site to become a multi lingual site and in doing so I've made the following change to the structure.
oldwebsite.net/somefile.php >> newwebsite.com/xx/somefile.php
oldwebsite.net/somefolder/somefile.php >> newwebsite.com/xx/somefolder/somefile.php
Now, I know how to do individual 301 redirects, but I got tons of pages and the new structure hasn't changed the page name so I would like to avoid setting up hundreds of individual 301 redirects, help!!
Thanks,
Mikael
You can put this code in your oldwebsite htaccess (which has to be in root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} oldwebsite\.net$ [NC]
RewriteRule ^(.*)$ http://newwebsite.com/xx/$1 [R=301,L]
I have a machine I'm leasing that was assigned an IP address that must have previously been assigned to some kind of link spamming company. Said company has hundreds of domains that still resolve to the IP address of my server, and Google and the like are constantly attempting to index the site with their bots (hundreds of thousands of pages). I've been unsuccessful in getting said link spammer to change their DNS records to resolve elsewhere. Fine.
I decided I could use mod_rewrite to deal with this in a fairly direct manner: I want any request that doesn't include one of my domain names to return 410, unless the request is for /robots.txt. For the robots file I want to return a simple file that disallows everything with a 200. By my thinking I can quickly extinguish the bots and return to normal.
My mod_rewrite configuration looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^.*foo\.com$
RewriteRule ^/robots\.txt$ /robots-off.txt [L]
RewriteCond %{HTTP_HOST} !^.*foo\.com$
RewriteRule !^/robots\.txt$ - [G]
Where all of the domains I might host on this IP fall somewhere under/at the foo.com domain. So I would expect the first rule to tell Apache to output the contents of /robots-off.txt with a 200 whenever a request is made for /robots.txt for any domain other than my own.
Sadly what's happening is that every request results in a 410, so the bots never get the chance to learn why that they should stop indexing the entire site. Here is the response when I query the wrong host:
The requested resource<br />/robots-off.txt<br />
is no longer available on this server and there is no forwarding address.
Please remove all references to this resource.
This has been going on for over a week with no end in sight. The first rule is running, but the [L] seems to be ignored and the second rule is then run. I don't understand why.
OK, I misunderstood how [L] works. See here: mod_rewrite seems to ignore [L] flag
The working code looks like this:
RewriteCond %{HTTP_HOST} !^.*foo\.com$
RewriteRule ^robots\.txt$ /robots-off.txt [L]
RewriteCond %{HTTP_HOST} !^.*foo\.com$
RewriteRule !^robots-off\.txt$ - [L,G]
Hope this helps somebody.
It's a bit late, but this would return a redirect to the browser, the browser would then re-request robots-off.txt this would be a new request and so again be rewritten. However if you do a pas-through then apache will return the final file inline and so no new request is made and the last is honoured in the way you expect.
RewriteCond %{HTTP_HOST} !^.*foo\.com$
RewriteRule ^robots\.txt$ /robots-off.txt [PT,L]
RewriteCond %{HTTP_HOST} !^.*foo\.com$
RewriteRule !^robots-off\.txt$ - [L,G]
I have this code:
# Use WordPress subdomain
RewriteCond %{HTTP_HOST} domain.co.uk
RewriteCond %{REQUEST_URI} ^/wp/(.*)$
RewriteRule .* http://wp.domain.co.uk/%1 [L]
This works, exactly how I want it to, so when you go to domain.co.uk/wp/index.php it shows the page wp.domain.co.uk/index.php.
However, rather than it redirecting you in the browser to the physical address wp.domain.co.uk/index.php I would like it to display domain.co.uk/wp/index.php.
Is that possible?
Thanks,
Ian
If the domain.co.uk and wp.domain.co.uk domains don't share a common document root (or if the latter isn't in a subdirectory of the former), you'll need to rely on mod_proxy. This won't work unless you have mod_proxy enabled. You'll just need to add a P flag to your RewriteRule:
RewriteRule .* http://wp.domain.co.uk/%1 [L,P]
Otherwise, if they share the same document root, just remove the http://wp.domain.co.uk and point it to the appropriate place within your document root.
I have a php application that serves multiple customers. Code is placed in the domain's root and is shared for all customers. Each customer can access it's page by using query string parameter "id".
I need advice and a sample code how to achieve this routing via mod_rewrite or it' better way to do it through php routing script:
Home page:
www.example.com/customerA --> www.example.com/customerA/main?id=1
www.example.com/customerB --> www.example.com/customerB/main?id=4
Note: "main" is main.php file not displaying file extensions.
Customer subfolders are not the real ones.
Inner pages are using additional parameters like:
www.example.com/customerA/page1?id=1&par1=5
On SERVER SIDE all rewrites should be interpreted as www.example.com/main?id=4
without virtual subfolder.
Thanks.
Here's what should work:
RewriteRule ^/customerA /customerA/main?id=1 [QSA,NC,R=301,L]
RewriteRule ^/customerB /customerB/main?id=4 [QSA,NC,R=301,L]
RewriteRule ^/(customer(A|B))/main /main [QSA,NC]
Now that's I've answered precisely to your question, I'm pretty sure it's not what you want.
If you have a lot of customers, I've made a huge answer here of a question that was about films, but you it's about customers, but the principle is exactly the same.
If you want to be more generic:
# if URL is not a real file...
RewriteCond %{SCRIPT_FILENAME} !-f
# if URL is not a real folder...
RewriteCond %{SCRIPT_FILENAME} !-d
# ...and if adding "php" points to a real file...
RewriteCond %{SCRIPT_FILENAME}.php -f
# ...then rewrite internally with "php" extension:
RewriteRule (.*) $1.php [QSA,NC]
Hope this helps.
I have a website build on jQuery scrollTo plugin. Each page is accessible via anchor's, ie.
www.domain.com/#page-one
and deeper
www.domain.com/#page-one--some-content.
I'd like to create rule with mod_rewrite so address like
www.domain.com/page-one
or
www.domain.com/page-one/some-content
point to the above one. Its quite easy with [R=301] flag but I need my "clean" address /page-one/some-content to stay in address bar not changing to #page-one--some-content.
Why I need to change them? Because for some reasons I need to use alternative site for MSIE and Opera, kind of regular one with reloading every page. I need the same links for both sites which is obvious, I think.
I spent lots of time digging & reading about anchors in URL's and stuff, but I haven't reach my goal. If any one can help me, I'll appreciate!
Thanks, Kuba.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule (.*) /index.php#$1 [NE]
This works excellent for me.