htaccess - What is rewrite rule for a wildcard string after the base?
For instance, I want www.example.com/mr.chase
to redirect to www.exapmle.com/index.php?name=mr.chase
Currently, I use a symbol (a period) so that it matches a symbol first before checking the rule.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^\.([^/]+)/?$ index.php?name=$1 [NC]
The above works. However, if I remove the \.
, it will APPEAR to work (successfully redirects), but I receive values I do not expect.
I use PHP, and find that $_GET['name'] produces index.php
instead of mr.chase
.
I only have issues grabbi开发者_开发技巧ng my GET variables when the base is a wildcard, and there is nothing else to match. Insight would be great! I apologize if I'm on the wrong track here.
I don't understand your example, and neither what the \.
and not matching discussion was about. But to prevent index.php
from showing up as parameter a simple assertion should do:
RewriteRule ^(?!index.php)([\w.]+)/?$ index.php?name=$1 [L]
# ^ ^
# | |
# exclude |
# only letters and dots
If that doesn't work it's an issue with your setup (FastCGI sometimes incurs additonal rewriting). Or another RewriteRule matches (= clear everything but above example, and the .htaccess files in upper directories). And for further debugging look into $_SERVER["QUERY_STRING"]
and the other variables for details.
Set up the RewriteLog
if you cannot find the cause with these tips.
It's because of your ^ matching the begginning of the string. It's looking for a period as the first character. Remove the ^
Also, a better pattern may be this:
/(.*?\.?([^/]+))/?$
This will match 'mr.chase' instead of just '.chase'
精彩评论