i hate asking for help, but...

Discuss practical ways rearrange URLs using mod_rewrite.

i hate asking for help, but...

Postby gnznroses » Fri Apr 25, 2008 1:15 pm

i can't figure this out.

i have a url like this:
http://sub.mysite.com/?name=johndoe

that i want to turn into this:
http://sub.mysite.com/redirect.php?name=johndoe


i want the rule to only apply if the name starts with a letter and contains only letters/numbers

i have this:

Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^name=([a-zA-Z][a-zA-Z0-9]+)$ redirect.php?name=$1 [NC,R]


but it's not kicking in.
any help greatly appreciated. read all the guides, but can't figure it.
gnznroses
 
Posts: 6
Joined: Fri Dec 07, 2007 4:47 pm

Postby Xian Zhu Xuande » Fri Apr 25, 2008 1:43 pm

The RewriteRule pattern does not match against query strings. :)

Apache 2.0: mod_rewrite wrote:Note: Query String
The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable. You can, however, create URLs in the substitution string, containing a query string part. Simply use a question mark inside the substitution string, to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine a new query string with an old one, use the [QSA] flag.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html


Here's an example of someone playing with it:
http://www.webmasterworld.com/forum92/6300.htm
Xian Zhu Xuande
 
Posts: 1
Joined: Fri Apr 25, 2008 12:25 pm

Postby gnznroses » Fri Apr 25, 2008 3:12 pm

oh, ok ;)

if it'll help anyone who sees this later, here's how i did it:


Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^name=([a-z][a-z0-9]+)$ [NC]
RewriteRule ^$ /redirect.php?name=%1 [R=301,L]
gnznroses
 
Posts: 6
Joined: Fri Dec 07, 2007 4:47 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 17 guests

cron