Rewrite Rule help :(

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 7
Joined: 31 Jan 2013, 16:56

Rewrite Rule help :(

31 Jan 2013, 16:59

Hi there,

So sorry to bug everyone with what I am sure is a basic question, but I am tearing my hair out as I have never used this module before :(.

I basically need to create a simple rewrite rule which converts :

/blog.asp?title=the-blog-title-here

to :

/blog/the-blog-title-here

Can anyone help? I will be eternally thankful.

Thanks so much,
T

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

Re: Rewrite Rule help :(

31 Jan 2013, 22:08

Hello,

try using the following:

Code: Select all
RewriteEngine on
RewrteBase /

RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp% /blog/%1? [Nc,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/]+)$ /blog.asp?title=the-blog-title-here [NC,L]


Regards
Andrew

User avatar
Posts: 7
Joined: 31 Jan 2013, 16:56

Re: Rewrite Rule help :(

31 Jan 2013, 22:55

Ah thanks so much Andrew.

Now sadly this didn't quite work, but getting somewhere... Also sorry just to be clear in my example the string I included is a variable so for example these would be a couple of examples of the re-write requirements (ie the title entry changes) :

/blog.asp?title=the-blog-title-here
/blog.asp?title=another-example-title

to (respectively) :

/blog/the-blog-title-here
/blog/another-example-title

(But naturally behind the scenes the page that it really needs to be querying, for dynamic content, is the original blog.asp?title=another-example-title, etc.)

Now, I have this, which is sort of working...

RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp$ blog/%1/? [NC,R=301,L]

BUT the problem I am having is that it is swapping the "-" for "%252D" as below :

/blog/another%252Dexample%252Dtitle/

And also, even if I physically type in: /blog/another-example-title it doesn't actually pull the content as if you were viewing : blog.asp?title=another-example-title

So sort of getting somewhere, but then not really!

So sorry to be such a pain, I am sure this is probably basic stuff for most - it is just such unfamiliar territory for me :(.

Many thanks again,
Tonya

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

Re: Rewrite Rule help :(

31 Jan 2013, 23:32

Hello,

That's encoding issue, try playing around with NE or NU flags. Their meanings are described here
The rule that has encoding issue is the first one, redirect. As the value of the variable is changed by the first one, the second one doesn't work too.

Regards
Andrew

User avatar
Posts: 7
Joined: 31 Jan 2013, 16:56

Re: Rewrite Rule help :(

01 Feb 2013, 08:06

Thanks Andrew that's so much appreciated - I will have another play :)

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: Rewrite Rule help :(

01 Feb 2013, 13:24

I suspect from the last comment that what you actually want to do is to rewrite the URLs in the *opposite* way from what you stated, e.g. the end-user keys:

www.example.com/blog/the-blog-title/here

and you want it to serve:

www.example.com/blog.asp?title=the-blog-title-here

Yes?

If so, you need:

RewriteRule blog/(.*)$ blog.asp?title=$1 [and whatever flags you need]

User avatar
Posts: 7
Joined: 31 Jan 2013, 16:56

Re: Rewrite Rule help :(

02 Feb 2013, 10:09

Hi there,

You are so right, and so sorry for the confusion caused there!!

What you have suggested works absolutely perfectly - so thank you sooooo much :). Star!!

Tonya

User avatar
Posts: 7
Joined: 31 Jan 2013, 16:56

Re: Rewrite Rule help :(

02 Feb 2013, 18:28

Hello again,

Sorry, just wanted to check, for SEO reasons really, so now if I visit :

Link example 1 : http://www.example.com/blog/the-blog-title-here

It is of course in fact processing :

Link example 2 : http://www.example.com/blog.asp?title=t ... title-here (And I can of course still visit this link directly, and it still works)

BUT I just wondered, for SEO, is it bad that both these link formats are actually accessible simultaneously, and if so, is there a way of then setting another rule to say...

If you visit this link version 1 : /blog.asp?title=the-blog-title-here it then re-directs you in the address bar to link version 2 : /blog/the-blog-title-here

SO, in the browser address bar and in any search results, it would then ensure that it is this version which appears: /blog/the-blog-title-here

Hope I am making sense :P.

Many thanks again,
Tonya

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

Re: Rewrite Rule help :(

03 Feb 2013, 15:05

Yes, having 2 URL that server the same content - is duplicating content, which is bad for SEO.
That was the reason I provided you with 2 rules: 1) to make your URLs look nice, 2) to hide the old ugly URLs

Regards
Andrew

User avatar
Posts: 7
Joined: 31 Jan 2013, 16:56

Re: Rewrite Rule help :(

03 Feb 2013, 20:44

Hi Andrew,

Thanks for your reply, and so sorry for my dumbness on this :(!

Basically I had been unclear on my requirements originally, as someone else in this post then pointed out. So that sadly meant that your rules weren't what I was aiming for (as I say totally my bad explanations, not your mistake).

So I know this is what you supplied :

------------------------

RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp% /blog/%1? [Nc,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/]+)$ /blog.asp?title=the-blog-title-here [NC,L]

------------------------

But basically this is what I have now :

RewriteRule blog/(.*)$ blog.asp?title=$1 [L]

(This basically makes this URL : /blog/entry-title-here to process /blog.asp?title=entry-title-here).

So I just need the rule which says if I manually access this format /blog.asp?title=entry-title-here to in turn jump me to /blog/entry-title-here

Now I have tried adding in those additional elements you included (and tweaked to try different things) to handle this double URL problem, but sadly it is not quite working.

Please could you let me know what additional rules I need to add to the above to handle this :). God I hope I am making sense!!

Thanks so much,
Tonya

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

Re: Rewrite Rule help :(

04 Feb 2013, 00:29

Tonya, everything you need is already there. If you'd look more carefully, the rule you use is the second one from those I suggested(mine just has 2 additional conditions, just in case). The first one achieves the results you need. It's just that I made a small typo there, replace '%' with '$' as in the following:

Code: Select all
RewriteCond %{QUERY_STRING} ^title=([^&]+)$ [NC]
RewriteRule ^blog\.asp$ /blog/%1? [NC,R=301,L]


Regards
Andrew

User avatar
Posts: 7
Joined: 31 Jan 2013, 16:56

Re: Rewrite Rule help :(

04 Feb 2013, 13:04

My god, I am so sorry - what a total muppet I am!!! You are right I should have noticed that!!!! I am definitely getting more familiar with all this now...

Thanks so much Andrew - you are a total star and your help is SOOOOOOO much appreciated :D.

Tonya

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests