So I'm going straight to business. Both tested and confirmed on XAMPP (Windows 7 32-Bit) and MAMP (OS X Snow Leopard), both newest versions. I have the following site structure:
/op/.htaccess
/op/index.php
/op/profile.php
The paths are the absolute paths from Apache document root.
My .htaccess file looks like this:
RewriteEngine on
RewriteRule ^[a-zA-Z0-9]+$ profile.php?alias=$1
When I request the site via http://localhost:8888/op/ the document index.php is opened. That's okay. When I request via http://localhost:8888/op/example the document profile.php is opened, that's also fine. And there is set up a GET parameter with the name alias just like desired. But it's value is simply empty! Like t开发者_如何转开发his:
http://localhost:8888/op/profile.php?alias=
So I just want to pass on the last part of the url as a GET variable that it looks like this for the server:
http://localhost:8888/op/profile.php?alias=example
I am slowly getting desperate. I am fighting with this since two and a half hours now. Either it is a wrong server configuration or a real silly mistake. I guess it's the regular expression, but I just don't get it.
It's a regex thing, your htaccess should look like this:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)$ profile.php?alias=$1
The $1
at the end of the string matches the first sub-pattern, but you didn't indicate any sub-pattern. The first set of parenthesis is the first sub-pattern.
Additionally, you may wish to indicate a RewriteBase
RewriteEngine on
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)$ profile.php?alias=$1
精彩评论