homepage Welcome to WebmasterWorld Guest from 107.22.78.233
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Again som rewrite/redirect
Sorry for it
SzosszeNET




msg:4506969
 4:25 pm on Oct 11, 2012 (gmt 0)

Hello, thanks for reading, and sorry if my question sounds stupid, I'm a bit noob to apache at the moment.

In nutshell we have a typo3 site with realurl where couple domains are configured (thus we need to stick to those domains). But the company also did buy plenty other top level domains.

The scenario would be the following : allow the few configured domains to work as requested (ie example.com - no rewrite, example.co.uk no rewrite, example.nl - no rewrite).
But rewrite or redirect (we I actually don't know which is more beneficial this case - assume the redirect as if I just rewrite I have to rewrite until the user leaves) any other preferably not one-by-one configured domain to example.com.

Just to visualize :

example.* ---> example.com
example.com ---> example.com
example.co.uk ---> example.co.uk
example.nl ---> example.nl

Thank you for your help in advance, hope I made everything clear.

 

g1smd




msg:4506976
 4:35 pm on Oct 11, 2012 (gmt 0)

The example.* rule must be last otherwise it also redirects the .nl and .co.uk requests.

What about the www. versions of all of those?

SzosszeNET




msg:4506977
 4:48 pm on Oct 11, 2012 (gmt 0)

Hello g1smd,

Hope I understood you well, I'm purely speaking about a website (www) although you are right I did miss the www.
Apparenly the domains at the registrar are in minimal config (only A-record is defined) for the example.* domains.

Probably this case than I need to check if www.example.* or example.* was requested and also rewrite that - an extra rule, cond?

What I tried :
created two vhost : default-catch and configured-domains.

default-catch :

<VirtualHost *:80>
DocumentRoot /var/www/www-empty/ #empty dir to make apache not complain
<Directory />
AllowOverride None
Order Deny,Allow
Deny from all
</Directory>

ErrorLog /var/log/apache2/default-error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/custom-access.log combined
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.example\.*)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
</VirtualHost>


configured-domains :

<VirtualHost *:80>
ServerName example.com
ServerAlias example.co.uk
ServerAlias example.nl
</VirtualHost>



But nothing is happening... I open example.biz I get there...

g1smd




msg:4506978
 4:51 pm on Oct 11, 2012 (gmt 0)

www\.example\.* matches
www.example
www.example.
www.example..
www.example...
www.example....
www.example.....
www.example...... etc.

SzosszeNET




msg:4506979
 4:54 pm on Oct 11, 2012 (gmt 0)

I was not clear than. :)

Indeed it does match so for every single domain I should get example.com. But I get the requested domain....No rewrite does happen.
And I'm not shure anymore that the best approach is two vhost, but I just cannot figure out the right solution.

lucy24




msg:4507136
 12:20 am on Oct 12, 2012 (gmt 0)

www\.example\.* matches
www.example
www.example.
www.example..
www.example...
www.example....
www.example.....
www.example...... etc.

The point here is that either your code has a typo or you're not up to speed on Regular Expressions-- but either way it makes no difference to mod_rewrite because Apache is very very unforgiving. And so are Regular Expressions.

Presumably what you meant was

www\.example\..+

which is still wrong-- but now it's only functionally wrong, not structurally.

:: thinking ::

In htaccess it would be

RewriteCond %{HTTP_HOST} example\.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} example\.co\.uk
RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk$
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L]

et cetera for each of the "good" domains. (I do not know what you do with HTTP 1.0 requests that come through without a domain name-- the ones that usually get covered with
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
but someone else will explain it.)

Do they all live on the same server? That is, will the correctly redirected requests pass through the same config file as the ones that arrive "cold"? This makes a huge difference in how you need to set up the redirects.

How many names are being redirected? If it isn't a vast number, it may be simpler to approach it from the other side:

RewriteCond %{HTTP_HOST} (exaple|exammple|xeample)
RewriteRule (.*) http://www.example.com/$1 et cetera.

That is, instead of excluding the "good" domains you name the "bad" ones.

SzosszeNET




msg:4507723
 10:59 am on Oct 13, 2012 (gmt 0)

Hello Lucy,

I started with "I'm noob on apache". :)

Running a web server is quite new for me also the expressions.

Regarding your question due to someone dreams, they have approx 20+ TLD, and only like 5 is configured on realurl.

So the best approach would be to configure the 5 ones not to touch when requested (example.com, .co.uk, etc).

And rewrite/redirect any other to .com.

As I understand this case I have to define the good domains first and the general rewrite for last.

good domain conf1
good domain conf2
good domain conf3
...

general redirect .** to .com

Thank all of you for the valuable hints, I'll try to do it. ;)

Cheers

SzosszeNET




msg:4507725
 11:35 am on Oct 13, 2012 (gmt 0)

Lucy,

Missed one of your questions : yes one webserver, multiple TLD + an other domain what we have. All A records point to the webserver.

So what I need to be 100% accurate:

#good domains
domain1.TDL1 conf
domain1.TDL2 conf
...

#general rewrite
domain1.*** conf #catch any other TLD and rewrite to domain1.com
domain2.*** conf #catch any TDL and rewirite to domain2.com


What I have no in my .htaccess :

#Domain config

#Good domains

RewriteCond %{HTTP_HOST} example\.co.\.uk
RewriteCond %{HTTP_HOST} !^www\.example\.co.\.uk$
RewriteRule (.*) http://www.example.co.\.uk/$1 [R=301,L]

#General redirect all TLD to .com (.* --> .com)

RewriteCond %{HTTP_HOST} example\.
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


Now at least rewrite happens, but evrything goes to .com instead of leaving .co.uk as it is...

lucy24




msg:4507729
 1:17 pm on Oct 13, 2012 (gmt 0)

Urk! Where did
\.co.\.uk
come from? In the pattern it should be simply \.co\.uk
And in the target .co.uk unless your cat stepped on the keyboard.

Now at least rewrite happens, but evrything goes to .com instead of leaving .co.uk as it is.

So it really is one domain name and a gazillion different tld's? I thought you were just making that up to fit into the example.something pattern.

.co.uk is getting picked up along with everything else because you haven't told the RewriteRule not to pick it up. Once its name is in exactly the right form it will bypass the .co.uk redirect rule and hit the universal rule instead. Your final rule therefore needs one more condition:

RewriteCond %{HTTP_HOST} !www\.example\.(com|co\.uk|nl)$

listing all the Good versions of example. This will filter out the ones that are already correct, leaving only the ones that need redirecting. That applies equally to

example.com:8080
and
www.example.su

Same redirect for both.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved