rewrite query string

Discuss practical ways rearrange URLs using mod_rewrite.

rewrite query string

Postby nikki » Mon Sep 28, 2009 1:15 pm

Hi,

I'm trying to rewrite/redirect page.php?kw=x to x.php, but I don't want users to be able to directly access x.php unless they've been redirected there from page.php?kw=x. Thus far I'm up to
Code: Select all
RewriteRule ^([^/]+).php$ landing.php?kw=$1 [QSA,L]

but the redirect is giving me problems.

I was also wondering if there's a way to strip everything but letters from the variable x, and to replace spaces with hyphens?

Could anyone help please? This is driving me mad :)
nikki
 
Posts: 3
Joined: Wed Aug 26, 2009 12:22 pm

Postby richardk » Mon Sep 28, 2009 2:06 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^([^/]+)\.php$ /landing.php?kw=$1 [QSA,L]


I was also wondering if there's a way to strip everything but letters from the variable x, and to replace spaces with hyphens?

You would have to handle that with PHP. If you remove/replace it when you output the link you have to do the opposite in landing.php.
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: Google [Bot] and 1 guest

cron