CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Apache configuration (http://www.codingforums.com/forumdisplay.php?f=69)
-   -   Help with .htaccess RewriteRule regex (http://www.codingforums.com/showthread.php?t=280845)

>ssp-cdr< 11-04-2012 06:16 PM

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

nomanic 11-04-2012 08:19 PM

could you use

RewriteEngine on
RewriteRule ^profile/(.*).html$ /index.php?username=$1 [QSA,L]

>ssp-cdr< 11-04-2012 11:35 PM

That doesn't fit my specific case.


All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.