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
^(.*)$ ?