using variables is causing internal server error

Discuss practical ways rearrange URLs using mod_rewrite.

using variables is causing internal server error

Postby LobsterMan » Thu Jul 02, 2009 5:43 am

I'm trying to redirect pagename.asp?id=2 to pagename-2.asp.html

Here's what I have:
Code: Select all
RewriteCond %{query_string} ^id=([0-9]+)$
RewriteRule (.*)\.asp $1-%1.asp.html [L]

It breaks and I get a error 500

Interestingly enough:
$1.asp.html works
%1.asp.html works
$1/%1asp.html works
$1/%1.asp.htmldoesn't work

What am I doing wrong? and how can I fix this?
LobsterMan
 
Posts: 1
Joined: Thu Jul 02, 2009 5:33 am

Postby richardk » Fri Jul 03, 2009 8:52 am

Your regular expression matches /abc-123.asp.html and a loop occurs.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?id=([0-9]+)(&.*)?$ [NC]
RewriteRule ^([^/]+)\.asp$ /$1-%1.asp.html? [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 25 guests

cron