redirect not working

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

redirect not working

14 Apr 2012, 07:36

Hi,

am quite new to isapi rewrite and any kind of url rewrite. I set up a small test file but only the rewrite part of it (last line) works. The redirect does not work. Here my code:


Code: Select all
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.89

#enabling rewrite.log
#RewriteLogLevel 9
#enabling error.log
#LogLevel debug

RewriteEngine on
#RewriteBase /

RewriteCond Host: www\.pet-needs\.de
RewriteRule ^([^./]+)\.asp?m__id=2&ani=1&pag=(.*) royal-canin/katzen/$2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^royal-canin/katzen/(.*)$ index.asp?m__id=2&ani=1&pag=$1 [L]


for better understanding, incoming url from linking pages:

http://www.pet-needs.de/index.asp?m__id=2&ani=1&pag=1

should be redirected to:

http://www.pet-needs.de/royal-canin/katzen/1

The only variable that would change for the redirect is pag=, all the others (m__id, ani) remain the same all the time.

Can anyone help me get this working?

Thanks,
Pascal

ps: strange enough, hours later even the working part does not work anymore... :?

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

16 Apr 2012, 06:11

Hi,

Would it maybe be possible that someone from Helicon would have a look at it with remote access? If I get this to work in the way I want for this one site, then I would need a full license because I have about 5 different sites each with a few houndreds of redirects. I tried ape first, but here the rewrites don't even fire (no logging in the files even at lvl 9).

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

16 Apr 2012, 19:07

Hello,

The correct syntax would be:

Code: Select all
RewriteCond %{HTTP:Host} ^www\.pet-needs\.de$ [NC]
RewriteCond %{QUERY_STRING} ^m__id=2&ani=1&pag=(.*)$ [NC]
RewriteRule ^([^./]+)\.asp$ royal-canin/katzen/%1? [NC,R=301,L]


Sure, we provide online assistance and can do everything for you under the terms of Premium Support Plan, see here

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

16 Apr 2012, 19:33

still not working. I get a 404 every time when using the pretty url directly and the rewrite does not take place (url remains the ugly one). :(

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

17 Apr 2012, 06:44

Please, provide rewrite.log for the testing request.
Logging issues described in FAQ

Regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

20 Apr 2012, 06:28

Here it is:

Code: Select all
 (2) init rewrite engine with requested uri /royal-canin/katzen/1
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (3) applying pattern '^([^./]+)\.asp$' to uri '/royal-canin/katzen/1'
 (3) applying pattern '^([^./]+)\.asp$' to uri '/royal-canin/katzen/1'

(2) init rewrite engine with requested uri /bildklein/royal_canin_kitten_main_coon.jpg
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri '/bildklein/royal_canin_kitten_main_coon.jpg'
(3) applying pattern '^([^./]+)\.asp$' to uri '/bildklein/royal_canin_kitten_main_coon.jpg'

 (2) init rewrite engine with requested uri /index.asp?m__id=2&ani=1&pag=1
 (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
 (3) applying pattern '^([^./]+)\.asp$' to uri '/index.asp'
 (3) applying pattern '^([^./]+)\.asp$' to uri '/index.asp'

(2) init rewrite engine with requested uri /bildklein/royal_canin_kitten_main_coon.jpg
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri '/bildklein/royal_canin_kitten_main_coon.jpg'
(3) applying pattern '^([^./]+)\.asp$' to uri '/bildklein/royal_canin_kitten_main_coon.jpg'


1 test for both new and old url. The new url generates a 404, the other just loads and doesn't change to pretty url.

Regards,
Pascal

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

20 Apr 2012, 06:44

Simple. Uncomment "#RewriteBase /" )))

Regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

20 Apr 2012, 08:00

Great Andrew. Thx. That makes the redirect work but I still have the problem with the 404 error showing up with the rewritten pretty url...

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

20 Apr 2012, 10:58

Well according to your log there's no such pattern as has been provided: ^royal-canin/katzen/(.*)$.
(2) init rewrite engine with requested uri /royal-canin/katzen/1
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri '/royal-canin/katzen/1'
(3) applying pattern '^([^./]+)\.asp$' to uri '/royal-canin/katzen/1'


This means you don't have that rule in config file, or it hasn't been read, etc.
If not, please, provide both rule and the rewrite.log for testing request.

Regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

20 Apr 2012, 15:12

ok, now I got that part working too. But if I want to add another rule it's not working correctly as it does not add the last variable (the number at the end for the page)

I tried this:
Code: Select all
RewriteCond %{HTTP:Host} ^www\.pet-needs\.de$ [NC]
RewriteCond %{QUERY_STRING} ^m__id=2&ani=1&pag=(.*)$ [NC]
RewriteRule ^([^./]+)\.asp$ royal-canin/katzen/%1? [NC,R=301,L]

RewriteCond %{HTTP:Host} ^www\.pet-needs\.de$ [NC]
RewriteCond %{QUERY_STRING} ^m__id=2&ani=2&pag=(.*)$ [NC]
RewriteRule ^([^./]+)\.asp$ royal-canin/hunde/%1? [NC,R=301,L]


and this:

Code: Select all
RewriteCond %{HTTP:Host} ^www\.pet-needs\.de$ [NC]
RewriteCond %{QUERY_STRING} ^m__id=2&ani=1&pag=(.*)$ [NC]
RewriteRule ^([^./]+)\.asp$ royal-canin/katzen/%1? [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^m__id=2&ani=2&pag=(.*)$ [NC]
RewriteRule ^([^./]+)\.asp$ royal-canin/hunde/%1? [NC,R=301,L]


to no avail.

it always changes to pet-needs.de/royal-canin/hunde/
the 1st rule fires correctly to pet-needs.de/royal-canin/katzen/1 (or whatever number it needs)

the correct page is shown when entering the pretty url directly as adding the following line right befind the 1st one works.

RewriteRule ^royal-canin/hunde/(.*)$ index.asp?m__id=2&ani=2&pag=$1 [L]

Regards,
Pascal

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

23 Apr 2012, 05:50

Can't say anything without rewrite.log for testing request.

Regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

23 Apr 2012, 09:03

Here it comes:


(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'royal-canin/hunde/'
(3) applying pattern '^([^./]+)\.asp$' to uri 'royal-canin/hunde/'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'royal-canin/hunde/'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'royal-canin/hunde/'
(1) Rewrite URL to >> /index.asp?m__id=2&ani=2&pag=
(2) rewrite 'royal-canin/hunde/' -> '/index.asp?m__id=2&ani=2&pag='
(2) internal redirect with /index.asp?m__id=2&ani=2&pag= [INTERNAL REDIRECT]

(2) init rewrite engine with requested uri /bildklein/royal_canin_kitten_main_coon.jpg
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'bildklein/royal_canin_kitten_main_coon.jpg'
(3) applying pattern '^([^./]+)\.asp$' to uri 'bildklein/royal_canin_kitten_main_coon.jpg'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'bildklein/royal_canin_kitten_main_coon.jpg'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'bildklein/royal_canin_kitten_main_coon.jpg'

(2) init rewrite engine with requested uri /royal-canin/katzen/1
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'royal-canin/katzen/1'
(3) applying pattern '^([^./]+)\.asp$' to uri 'royal-canin/katzen/1'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'royal-canin/katzen/1'
(4) RewriteCond: input='\\?\D:\var\www\root_zotto\pet-needs.de\wwwroot\royal-canin\katzen\1' pattern='!-f' => matched
(4) RewriteCond: input='\\?\D:\var\www\root_zotto\pet-needs.de\wwwroot\royal-canin\katzen\1' pattern='!-d' => matched
(1) Rewrite URL to >> /index.asp?m__id=2&ani=1&pag=1
(2) rewrite 'royal-canin/katzen/1' -> '/index.asp?m__id=2&ani=1&pag=1'
(2) internal redirect with /index.asp?m__id=2&ani=1&pag=1 [INTERNAL REDIRECT]


User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

23 Apr 2012, 10:35

Well,

I edited your log to make it more readable.
Unfortunately, there wasn't any request to /index.asp?m__id=2&ani=2&pag=XXXX.

Regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

23 Apr 2012, 11:21

Well in fact they are included, else it would not be doing lines 1-8...

I treid another time and always get this: (the url tried by entering directly or via link: www.pet-needs.de/index.asp?m__id=2&ani=2&pag=1

Code: Select all
(2) init rewrite engine with requested uri /platform/sdl/discovery.svc
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'platform/sdl/discovery.svc'
(2) init rewrite engine with requested uri /royal-canin/hunde/
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'royal-canin/hunde/'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'royal-canin/hunde/'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'royal-canin/hunde/'
(1) Rewrite URL to >> /index.asp?m__id=2&ani=2&pag=
(2) rewrite 'royal-canin/hunde/' -> '/index.asp?m__id=2&ani=2&pag='
(2) internal redirect with /index.asp?m__id=2&ani=2&pag= [INTERNAL REDIRECT]

(2) init rewrite engine with requested uri /platform/sdl/discovery.svc
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'platform/sdl/discovery.svc'
(2) init rewrite engine with requested uri /platform/sdl/discovery.svc
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'platform/sdl/discovery.svc'
(2) init rewrite engine with requested uri /platform/sdl/discovery.svc
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'platform/sdl/discovery.svc'
(2) init rewrite engine with requested uri /royal-canin/hunde/
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'royal-canin/hunde/'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'royal-canin/hunde/'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'royal-canin/hunde/'
(1) Rewrite URL to >> /index.asp?m__id=2&ani=2&pag=
(2) rewrite 'royal-canin/hunde/' -> '/index.asp?m__id=2&ani=2&pag='
(2) internal redirect with /index.asp?m__id=2&ani=2&pag= [INTERNAL REDIRECT]

(2) init rewrite engine with requested uri /
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri ''
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri ''
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri ''
(2) init rewrite engine with requested uri /index.asp
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'index.asp'
(4) RewriteCond: input='www.pet-needs.de' pattern='^www\.pet-needs\.de$' => matched
(4) RewriteCond: input='' pattern='^m__id=2&ani=1&pag=(.*)$' => not-matched
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'index.asp'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'index.asp'
(2) init rewrite engine with requested uri /platform/sdl/discovery.svc
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'platform/sdl/discovery.svc'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'platform/sdl/discovery.svc'

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

24 Apr 2012, 04:58

Well, again... seems like there's no rule for m__id=2&ani=2&pag=(.*), there's only m__id=2&ani=1&pag=(.*) that has been checked:

(2) init rewrite engine with requested uri /index.asp
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^([^./]+)\.asp$' to uri 'index.asp'
(4) RewriteCond: input='www.pet-needs.de' pattern='^www\.pet-needs\.de$' => matched
(4) RewriteCond: input='' pattern='^m__id=2&ani=1&pag=(.*)$' => not-matched
(3) applying pattern '^royal-canin/katzen/(.*)$' to uri 'index.asp'
(3) applying pattern '^royal-canin/hunde/(.*)$' to uri 'index.asp'


You see, condition with host has been matched and condition for hunde querystring is omitted.

I suspect you need to follow this documentation to set necessary permissions for .htaccess file - permissions

regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

25 Apr 2012, 11:34

got it working:

the problem was this part:

Code: Select all
RewriteRule ^([^./]+)\.asp$ royal-canin/katzen/%1? [NC,R=301,L]

RewriteRule ^([^./]+)\.asp$ royal-canin/hunde/%1? [NC,R=301,L]

when changing it to:

Code: Select all
RewriteRule ^index\.asp$ royal-canin/katzen/%1? [NC,R=301,L]

RewriteRule ^index\.asp$ royal-canin/hunde/%1? [NC,R=301,L]


it works like a charm.

but one more question: I know there is chaining but it is interupted as soon as 1 rule is null.

but is it still possible to optimize such redirects for returning parts of strings?

what I mean:

ani=1 is always katzen
ani=2 is always hunde
ani=3 is always frettchen
aso

same for:
m__id=2 always royal-canin
m__id=3 always other-brand
aso

so would it be possible to "chain" these queries like:

checking for m__id first, if we find a match then go for ani and at the end set up the rule for rewriting with the found matches?
so in fact it would be like defining what the various variables would be first.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

26 Apr 2012, 07:02

Shoot! I must have noticed it before.

Do you mean that you'd like to set each variable one by one, depending on the value?
It'd be smth like this, using the mapfiles, see "Comprehensive mapfiles" in FAQ

Code: Select all
RewriteMap ASP_PAGE_mapfile txt:mapfile1.txt
RewriteMap ANImapfile txt:mapfile2.txt
RewriteMap PAQmapfile txt:mapfile3.txt

RewriteCond %{HTTP:Host} ^www\.pet-needs\.de$ [NC]
RewriteCond %{QUERY_STRING} ^m__id=([^&]*)&ani=([^&]*)&pag=.*$ [NC]
RewriteRule ^([^./]+)\.asp$ /${ASP_PAGE_mapfile:$1}/${ANImapfile:%1}/${PAQmapfile:%2}? [NC,R=301,L]

NOTE this is just an example to show a possible variant.

Each mapfile would contain numeric ID and the resulting name of the page.

Regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

26 Apr 2012, 11:24

in which folder do I have to create these mapfiles? same as httpd.conf?

Page cannot be found: ulr looks like this: http://www.pet-needs.de/%24%7bmapmid:%7 ... apani:%7d/

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: redirect not working

27 Apr 2012, 04:55

the map files are supposed to be in the same folder as the rules. If rules are in httpd.conf, than - beside the conf, if it's .htaccess - beside .htaccess.

The link provided is not the one you need to request. You need to request index.asp?m__id=XX&ani=YYY&pag=ZZZ and it should redirect to the correct URL. There's no need to request /${ASP_PAGE_mapfile:$1}/${ANImapfile:%1}/${PAQmapfile:%2}.

In case redirect doesn't happen, please, provide rewrite.log for the testing request.
Logging issues described in FAQ

Regards
Andrew

User avatar
Posts: 32
Joined: 14 Apr 2012, 07:28

Re: redirect not working

27 Apr 2012, 07:12

I know, the url given is the rewritten one, not the one i'm entering.

Code: Select all
(2) init rewrite engine with requested uri /index.asp?m__id=2&ani=2&pag=1
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(3) applying pattern '^index\.asp$' to uri 'index.asp'
(4) RewriteCond: input='www.pet-needs.de' pattern='^www\.pet-needs\.de$' => matched
(4) RewriteCond: input='/index.asp' pattern='^/index\.asp$' => matched
(4) RewriteCond: input='m__id=2&ani=2&pag=1' pattern='^m__id=2&ani=([^&]*)&pag=1' => matched
(1) escaping /royal-canin/${mapani:}/1
(2) explicitly forcing redirect with http://www.pet-needs.de/royal-canin/%24%7bmapani:%7d/1
(2) internal redirect with /index.asp?m__id=2&ani=2&pag=1 [INTERNAL REDIRECT]

Next

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 25 guests