Why does my URL append?

Discuss practical ways rearrange URLs using mod_rewrite.

Why does my URL append?

Postby worleyjbird » Mon May 19, 2008 2:07 pm

I want this URL:
http://localhost/?fuseaction=virtual.co ... index.html

To redirect to:
http://localhost/features/newsletters/pp35/

My results are *almost* correct:
http://localhost/features/newsletters/p ... index.html

Issue - I cannot figure out why '?fuseaction=virtual.content&area=sf_pints&content=fonts/pp35/index.html' is being appended, can anyone help me?

Here is my code:
RewriteCond %{QUERY_STRING} ^((.*)pints/pp35/index.html(.*))$ [NC]
RewriteRule ^.*$ features\/newsletters\/pp35\/ [L,NC,R]
worleyjbird
 
Posts: 8
Joined: Mon May 19, 2008 2:01 pm

Adding '?' to the end of the RewriteRule resolved my issue!

Postby worleyjbird » Mon May 19, 2008 2:40 pm

I added a '?' at the end of the RewriteRule. It works but I don't really understand why. In any case, I wanted to post this reply in case others need it.

RewriteRule ^.*$ features\/newsletters\/pp35\/? [R,NC,L]
worleyjbird
 
Posts: 8
Joined: Mon May 19, 2008 2:01 pm

Postby richardk » Mon May 19, 2008 3:15 pm

Because the query string is automatically appended for redirects and ? specifies an new empty query string (ie. do not append the old one).

You should not escape in the substitution part
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&?)content=pints/pp35/index\.html(&.*)?$ [NC]
RewriteRule .* /features/newsletters/pp35/? [NC,R,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 101 guests

cron