views:

28

answers:

2

hi,

I am trying to make my pages seo friendly.

I have a links in my page.

http://abc.com/test.php?Section=pages&title=feedback+%26+enquiry

it works fine and title has value "feedback & enquiry". I changed above link to:

http://abc.com/pages/feedback+%26+enquiry.htm

I wrote the htaccess code like:

Options +FollowSymLinks

RewriteEngine on
RewriteRule index.htm$ index.php
RewriteRule ^(.*)/(.*)\.htm$ /test.php?Section=$1title=$2 [R]

i expected the same the result but i was surprised to see the error as the title is having value or "feedbac" and new variable "enquiry" being created with value ""

I am being unable to find the error. I guess its the htaccess conversion error. so how can i make it work?

I tried backescaping but got internal server error. My new htaccess code:

Options +FollowSymLinks

RewriteEngine on
RewriteRule index.htm$ index.php
RewriteRule ^(.*)/(.*)\.htm$ index.php?Section=$1&title=$2 [R,B]

My Apache version is : 2.2.4

A: 

If you're running Apache 2.2, you can use the B flag to escape any backreferences in your rewritten URL:

RewriteRule ^pages/(.*)\.htm$ /test.php?title=$1 [R,B]

Otherwise, in Apache 2.0, you can try using the internal RewriteMap escape:

RewriteRule ^pages/(.*)\.htm$ /test.php?title=${escape:$1} [R]
Tim Stone
sorry it inform the lately change as i got error on my full url. I have edited my post and wrote my full url as i got internal server error while testing your given script with [B] options
KoolKabin
Tim Stone
i am not getting any error code only internal server error message. May the the webmaster has configured to not to show error code/message. I tried with both options but both failed. Keeping escape will send title = ""
KoolKabin
A: 

from the mod_rewrite doc:

Apache has to unescape URLs before mapping them, so backreferences ($1) will be unescaped at the time they are applied.

so your feedback+%26+enquiry.htm gets rewritten to test.php?title=feedback+&+enquiry, which, naturally, yields the result you see.

you can avoid the backreferences being unescaped by adding the 'B' (escape backreferences) rewrite flag to your RewriteRule:

RewriteRule ^pages/(.*)\.htm$ /test.php?title=$1 [R,B]
ax
sorry it inform the lately change as i got error on my full url. I have edited my post and wrote my full url as i got internal server error while testing your given script with [B] options
KoolKabin
make sure you do not have whitespace inside the `[R,B]`, ie. *not* `[R, B]`.
ax
um.... i am preety sure that i dun have white space between them but still getting error
KoolKabin