Trying to redirect to my php script using htaccess

Hi

I have gone over and over this but I can not get it to work.

I am trying to match this:

[b]http://villarentfethiye.simpg.net/17-vacationvillasfethiyerental.html[/b]

and send it to:

[b]http://simpg.net/info1.php?a=17[/b]

So I am using:


Options +SymLinksifOwnerMatch 
RewriteEngine On

RewriteCond %{HTTP_HOST} ^[.+].simpg.net/[0-9]+-[\\.0-9_-a-z]+\\.html$ [NC]
RewriteCond %{HTTP_HOST} !^www.simpg.net$ [NC]
RewriteRule ^[\\.0-9,-a-z]+\\.simpg.net/([0-9]+)-[\\.0-9_-a-z]+\\.html$ http://simpg.net/info1.php?a=%1 [NC,QSA,L]

But it is not working.

Because this first block is not catching the incoming url,
my second block gets it and sends it to the wrong page.

My second block should only match:

[b]http://villarentfethiye.simpg.net/[/b]

And re-direct to : http://simpg.net/info2.php?a=villarentfethiye

It uses:

RewriteCond %{HTTP_HOST} ^(.+).simpg.net$ [NC]
RewriteCond %{HTTP_HOST} !^www.simpg.net$ [NC]
RewriteRule ^.*$ http://simpg.net/info2.php?a=%1 [NC,QSA,L]

This second block works - BUT it should not be excepting
any url with data coming after “simpg.net” … but it does.

Because when the first block fails, the second is doing
a re-direct ( but to the wrong page )

Can anyone see where I have gone wrong ?

Thanks.

.

Hi Jekko!

First, you are in need of some information about how to correctly write code for mod_rewrite. Therefore, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

[noparse]http://villarentfethiye.simpg.net/17-vacationvillasfethiyerental.html => http://simpg.net/info1.php?a=17[/noparse]

WHY in the world would you use villarentfethiye as a subdomain? Does it even exist? Unless you REALLY need it, the first thing I would do is strip useless information from the URL (so you can actually hide the link with the query string). Then the code would be trivial:

# .htaccess in DocumentRoot

# strip useless domain information
RewriteCond %{HTTP_HOST} !^simpg\\.net$ [NC]
RewriteRule .? http://simpg.net%{REQUEST_URI} [L]

# Redirect to deliverable link
RewriteRule ^([0-9]+)-[a-z]+\\.html$ info1.php?a=$1 [L]

Please note that the {HTTP_HOST} variable does not contain a / nor a URI.

If you follow the above code, you’ll KNOW why your code was not working, i.e., {HTTP_HOST} and the subdomain you captured clearly did not contain digits.

Regards,

DK