I have a website on domain.com which has multilingual content in URLs e.g.:
domain.com/en for english
domain.com/de for german
domain.com/it for italian
etc. These are not really directories - these are just rewrites that rewrite to /index.php?lang=... So domain.com/lang/one/two/three is rewritten to /index.php?lang=$1&path=$2
It also has domain.com/assets directory that holds all the common files (css, images etc.)
Now I want to change that every language has its own domain which I think could be managed by using mod_proxy, mod_proxy_http and mod_proxy_html in Apache. What I want to achieve is that if user visits:
www.domain.com he gets content from domain.com/en
www.domain.de he gets content from domain.com/de
www.domain.it he gets content from domain.com/it
And if he visits /assets directory from any domain (.com, .de, .it) he would get content from domain.com/assets. Also if user visits URL e.g. www.domain.de/something he should receive content from www.domain.com/de/something
And the other thing are URLs which would have to be rewritten before output so for instance user that browses domain.de would never go to domain.com at all...
Is this possible? Otherwise we would have to reprogram whole CMS to work with different domain for every language...
It's possible. Just handle them in a single virtualhost and use RewriteCond to examine %{HTTP_HOST} and do the same rewrites you're already doing today. You can capture the country code and backreference it with %1.
Related
I registered a expired domain to forward all incoming links to another domain. The problem is: many inlinks are placed on subdomains, for example: axa-art.cdn.contento-v41.eu/axa-art/0eee9cec-58cb-45b2-a4e2-b5f73920068e_091216_axa+art_classic+car+study_de_rz.pdf
I am looking for a 301 redirect rule in htaccess that forward any url (no matter on main domain or subdomain) to "new-url.tld"
axa-art.cdn.contento-v41.eu
axa-art.cdn.contento-v41.eu/slug
any-subdomain.contento-v41.eu
any-subdomain.contento-v41.eu/slug
all of this example above should
forward to this exact URL: new-domain.tld
Question 1:
Is it possible to create a "general" rule and place it into htaccess of the main directory?
Question 2:
Or do i have to write a specific rule for each subdomain?
Question 3:
Do I have to create a sub-directory and create a separate htaccess in every sub-directory for each subdomain I want to add redirection-rules?
Help or suggestions are highly appreciated. Thank you very much for your help in advance.
This isn't just a .htaccess question. In order for your server to receive requests to <any-subdomain>.example.com the necessary DNS and server config directives need to be in place. If the request doesn't reach your server then you can't implement a redirect in .htaccess.
So, I suspect that these subdomains are not even resolving?
You either need to create the necessary DNS A records and ServerAlias directives one by one for each hostname (ie. subdomain) or create a "wildcard" DNS A record (and ServerAlias *.example.com directive in the vHost). But then you still have an issue with these hostnames being covered by an SSL cert if you need to redirect from HTTPS.
You can then create the necessary redirect in .htaccess. Although, since you need access to the server config (or a using a control panel that does this for you) to implement the directives above, you should also implement this redirect in the server config also.
For example, at the top of your .htaccess file, before the existing directives (or in your vHost):
RewriteEngine On
RewriteCond %{HTTP_HOST} !^new\.example$
RewriteRule ^ https://new.example%{REQUEST_URI} [R=301,L]
The above states... for any request that is not for new.example then 301 redirect to https://new.example/<same-url>.
However, if you have access to the server config and this other domain is configured in its own vHost container then the redirect can be simplified:
Redirect 301 / https://new.example/
UPDATE#1:
this rule does forward any URL form the main domain to the new domain.
# Permanent URL redirect- by netgrade
RewriteEngine on
RewriteCond %{REQUEST_URI} !https://www.marco-mahling.de/$
RewriteRule $ https://www.marco-mahling.de/ [R=302,L]
The rule I posted above should probably replace your existing rule entirely.
Yes, your rule does redirect every URL to the root of the new domain, but it is arguably incorrect. The RewriteCond directive is superflous and isn't actually doing anything. The REQUEST_URI server variable contains the URL-path, it never contains the scheme + hostname. So, the RewriteCond directive you've posted will always be successful.
If that is the rule you currently have then it would already redirect everything. In which case your problem would seem to the necessary DNS and server config directives as mentioned above.
From your directives, I assume that the other domain actually points to a different server (or different vHost on the same server). Otherwise, this would have resulted in a redirect-loop. In which case, you only need the much simpler Redirect directive that I posted above.
UPDATE#2: That works fine BUT the incoming links are still not forwarded cuz of a "%" in the url: https://axa-art.cdn.contento-v41.eu/axa-art%2F0eee9cec-58cb-45b2-a4e2-b5f73920068e_091216_axa+art_classic+car+study_de_rz.pdf
It's actually because of the %2F - an encoded slash (/) in the URL-path. By default, Apache will reject such URLs with a 404 (for security reasons).
To allow encoded slashes in the URL you would need to set AllowEncodedSlashes On in the server config (or vHost container). You cannot set this in .htaccess. (The server generated 404 occurs before .htaccess is even processed.)
However, I would express caution about enabling this feature. (Is there a specific requirement here? Are you recreating these documents on the new server?)
If this request was intended to map directly to a PDF file on disk then this actually looks like an incorrectly URL encoded request, since a slash / is not a permitted filename character on either Windows or Linux.
If you enable AllowEncodedSlashes then the above RewriteRule will redirect the request to /axa-art/0eee9cec....pdf - note the %-decoded / in the resulting URL. You would need to take additional steps to maintain the URL-encoding (if that was required), but as I say, that looks like a mistake to begin with.
I want to print a short, easy-to-type URL on paper brochures.
So that people can type example.com/foo into their smartphone browser, and the browser will display an existing page, say http://example.com/bar/yada.php .
I see that most pages about modrewrite involve regex, but what if I only need manually defined single pages?
Should I have an actual foo directory in the web root, containing a .htaccess file?
The following did what I needed, placed in the .htaccess at webroot.
An actual foo directory need not exist.
RedirectMatch 301 "(?i)^/foo$" "/bar/yada.php"
RedirectMatch 301 "(?i)^/foo/$" "/bar/yada.php"
I have a problem with a strange htaccess configuration
I have a main domain name assigned to a website, let's say domain.com.
I use Joomla 2.5.19 and the site is set up to serve a multilanguage website.
All is working smoothly, and I can reach each language automatically: if you look for the it language, the system redirect you to domain.com/it, if you look for en language, the system redirect you to domain.com/en, and so on.
Now I have a special needing: I have bougth the same domain with different extensions to serve each language: i.e., I would like that the system will automatically redirect each language to the correcrt domain suffix (for example, domain.com/it must be redirected to domain.it/it, and so on)
I have assigned each domain name as Alias of the main domain.com in Apache config file
I have tried several solutions, also reading the mod_rewrite and .htaccess manuals, but I can't reach the goal, because I can't configure each domain.com/language/ Joomla subdir to avoid it loops on itself in infinite mode :(
Is there a solutions for that?
Thank you all in advance
tI have found a simple but working trick.
I'll explain it in the case you have two languages, EN and IT
At first, I have set up two differents Apache vhosts:
- one for the main domain mysite.com (it will serve the EN language)
- one for the second "laguage dedicated" domain mysite.it (it will serve the IT language)
The two vhost records are quite identical and pointing to the same physical path.
The only differences are:
1) the ServerName declaration, respectively equal to www.mysite.com and to www.mysite.it
2) the line that acts the redirection:For mysite.com this line is:
RedirectMatch 301 ^/it/.*$ http://www.mysite.it/it/In this way the /it sub-structure is permanently redirected to the .it domainFor mysite.it this line is:
RedirectMatch 301 ^/en/.*$ http://www.mysite.com/en/In this way the /en sub-structure is permanently redirected to the .com domainThis simple architecture override the original multilingual structure, permitting you to serve any number of languages and correctly assigning them to the exact domain extension
Let's say I have a domain called www.customer1.com and www.customer2.com. I want to run all the pages of these sites separately... but items found within certain paths, I'd like to reference from one domain to another in a masked forwarded manner for SEO purposes and to avoid having to place files in two different FTP accounts.
The target folders are
/images
/pdfs
FOr example if a call is made to
www.customer2.com/images/[any image] then I want the masked forwarder to kick in to serve a file that is located at www.customer1.com/images/[filename requested]. Same goes for anything found after /pdf/ in the same example.
However all other pages should remain referencing to internal files within.
I have limited understanding of .htaccess and frankly lost as to how to approach anything beyond a very simple 30
Not sure you understand the concept here, as the "forwarding" would equate to an external redirect, there is no "masking" anywhere. The closest thing there is is reverse proxying:
RewriteEngine On
RewriteRule ^(images|pdf)/(.*)$ http://www.customer1.com/$1/$2 [L,P]
You need mod_proxy to do this and those rules need to be in the htaccess file in your customer2.com's document root.
You can also do this in customer2.com's server/vhost config:
ProxyPass /images/ http://www.customer1.com/images/
ProxyPass /pdf/ http://www.customer1.com/pdf/
I have a new website as http://abc.com/case_studies/casstudy20/.
I have an old website as http://xyz.com/clients/home.php?client=myclient
There are loads of case studies and stories under old domain that is xyz.com. Now that I am using abc.com is it possible to replace the URL, so it shows abc.com but access the code from the same old place.
meaning when my users goes to old site instead of xyz.com. It should say http://abc.com/clients/home.php?client=myclient. But runs from the same old xyz.com.
Is it possible to do it using htaccess.
Sort of. You can redirect all the traffic from xyz.com to the proper path on abc.com but this requires you to maintain control of both domains.
If you can, it's actually better to put this in the virtual host config for xyz.com then you don't need a complete configuration at all. Assuming you have permissions it will work in .htaccess as well though.
RedirectMatch ^(.*)$ http://www.abc.com$1
If you can keep control of both domains then you are looking for a http 301 redirect. You can do that by adding the following line to your htaccess file to redirect an entire website. Without control of your original domain it's impossible for your old xyz.com website to be routed to the appropriate server so your htaccess file will never have anything to redirect.
redirect 301 / http://abc.com/