Struggling with a simple rewrite

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 4
Joined: 17 Aug 2012, 10:25

Struggling with a simple rewrite

20 Aug 2012, 05:46

Hello All,

Please could you take a look at the following and let me know what I've missed. Here is my situation, I have a site where the default page (default.asp) does all the work. Different pages are returned depending upon the querystring values, the querystring pattern will always be -

/default.asp?id=2&p=page-title

I was hoping that the code below, would rewrite this to

/2/page-title

This part is working OK, but when I get to that page all links within it still contain the /2/, meaning that a link that should be written as /3/another-page-title, is actually written as /2/3/another-page-title, meaning that clicking on any link on /2/page-title just redirects to itself...

Here is my syntax --

Code: Select all
RewriteBase /

SeoRule default.asp\?id=(.+)(?:(?:&|&))p=([^&=]+)$ $1/$2 [NC,L]
RewriteRule ^(\d+)/.+$ /default.asp?id=$1 [NC,L]


Please let me know what i've missed.

Many thanks

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Struggling with a simple rewrite

20 Aug 2012, 06:06

Hello,

Please try to fix your config like this:

RewriteBase /

SeoRule default.asp\?id=(.+)(?:(?:&|&))p=([^&=]+)$ /$1/$2 [NC,L]
RewriteRule ^(\d+)/.+$ /default.asp?id=$1 [NC,L]

User avatar
Posts: 4
Joined: 17 Aug 2012, 10:25

Re: Struggling with a simple rewrite

20 Aug 2012, 06:51

That's great, thanks Anton, one final question, for all URLs not affected by this, that end with .asp, is there anyway of replacing the '.asp' with a '/'?

Thanks for your help :)

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Struggling with a simple rewrite

20 Aug 2012, 07:27

Hello,
Please try to have the following:

SeoRule ^(?!.*default\.asp)(.*)\.asp$ $1/ [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1.asp [NC,L]

If it doesn't work, please provide some examples of URLs you would like to be transformed this way.

User avatar
Posts: 4
Joined: 17 Aug 2012, 10:25

Re: Struggling with a simple rewrite

23 Aug 2012, 04:57

Hi Anton,

Thanks for this. so what I have is --

RewriteBase /
SeoRule default.asp\?id=(.+)(?:(?:&|&))p=([^&=]+)$ /$1/$2 [NC,L]
RewriteRule ^(\d+)/.+$ /default.asp?id=$1 [NC,L]
SeoRule ^(?!.*default\.asp)(.*)\.asp$ $1/ [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1.asp [NC,L]

But there seems to be an issue with this; assuming that I want to access test.asp at root level, if i'm already on 299/bulletin/duel-in-the-sun-at-hotel
When I click on the link to test.asp, i get sent to 299/bulletin/test/ instead of test/.

If i change to /test/ i Get a 500 'The requested page cannot be accessed because the related configuration data for the page is invalid.' Error.

Thanks for your help with this.

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Struggling with a simple rewrite

23 Aug 2012, 05:07

Hello,

So, the problem is with the base. Do you have base set on your pages?
And do you have root-relative or relative links on pages? Can you give some specific examples.

User avatar
Posts: 4
Joined: 17 Aug 2012, 10:25

Re: Struggling with a simple rewrite

23 Aug 2012, 06:28

Thanks Anton,

I've just set the base, and that has overcome the issue with the extra parameters in the url. However I'm still getting 500 Error when trying to access test.asp. The URL i'm using is just test.asp - no '/' and thne base is set as -

<base href="http://www.testmy.com" target="_blank" /> again no '/' at the end.

all of the other links are dynamic, so fall within the first set of rules.

Thank you

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Struggling with a simple rewrite

28 Aug 2012, 06:20

Hello,

So, you make a request to /test/ but you get 500 error instead of /test.asp?
If yes, please enable logging in httpd.conf by putting

RewriteLogLevel 9

and provide rewrite.log records for the request to /test/

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 24 guests