Htacces rewrite tld without changing subdomain or channels

I am trying to rewrite the following url:

subdomain must match any subdomain. same for TLD. both: http://car.example.com/ and http://cat.example.co.uk should be rewritten

http://subdomain.example.com/some/dir at http://subdomain.example.nl/some/dir

and http://example.com/some/dir at http://exampkle.nl/some/dir

(also with www.)

but my knowledge of htaccess and rewrite rules is generally not good enough for this :(

I hope one of you knows the solution.

ps. I tried the search;)

+5
source share
2 answers

, :

  • example.com → example.nl
  • example.co.uk → example.nl
  • sub.example.com → sub.example.nl
  • sub.example.co.uk → sub.example.nl

, , , TLD .nl( ), , www , ( " -, , , ), , . URL-, TLD.

RewriteEngine On
RewriteCond %{HTTP_HOST} !example\.nl$
RewriteCond %{HTTP_HOST} ^([^.]+\.)?example\.
RewriteRule ^ http://%1example.nl%{REQUEST_URI} [NC,L,R=301]

RewriteRule ^ URL-, RewriteCond () % 1 , , , 301, , URL- . (, "URL" ) .

+3

: EDIT: . , % 1 RewriteCond

RewriteEngine On
# Check if the hostname requested is subdomain.example.com or empty
# Now we attempt to capture the subdomain with (.*)? and reuse with %1
RewriteCond  %{HTTP_HOST} ^(.*)?example.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
# Rewrite it as subdomain.example.nl and redirect the browser
RewriteRule ^(.*) http://%1example.nl$1 [L,R,NE,QSA]

# Note: With the above edit for %1, this part should no longer be necessary.
# Then do the same for example.com, with or without the www
RewriteCond  %{HTTP_HOST} ^(www\.)?example.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://www.example.nl$1 [L,R,NE,QSA]
+2

All Articles