View Single Post
Old 11-04-2012, 06:16 PM   PM User | #1
>ssp-cdr<
Regular Coder

 
Join Date: May 2007
Posts: 100
Thanks: 16
Thanked 11 Times in 11 Posts
>ssp-cdr< is an unknown quantity at this point
Help with .htaccess RewriteRule regex

There's a page on my website to view a user's profile. The username is passed in through the URL and since that's all that's needed in the URL I simply pass it as the query string, such as http://example.com/profile/?manwithahat

I thought it would be nice to get rid of the question mark in the URL by using the Apache RewriteEngine, so the URL could be like this http://example.com/profile/manwithahat

But I am having trougble with the regular expression that RewriteRule needs. I thought I could use -
RewriteEngine on
RewriteRule ^(.*)$ ?$1 [QSA,L]
but this causes an internal server error.

Doing some testing I found that this will pass through a number the way I need it to -
RewriteEngine on
RewriteRule ^([0-9]+)$ ?$1 [QSA,L]
so that if the URL is http://example.com/profile/123456 then in PHP the $_SERVER['QUERY_STRING'] value becomes 123456. From this test I know that the overall structure of the RewriteRule is correct, it's just the regular expression that needs fixing.

What should be used instead of ^(.*)$ ?
__________________
The CodingForums Funny Images thread - http://www.codingforums.com/showthread.php?t=245405

Last edited by >ssp-cdr<; 11-04-2012 at 11:23 PM..
>ssp-cdr< is offline   Reply With Quote