繁体   English   中英

.htaccess的RewriteRule有什么问题

[英]Whats wrong with this RewriteRule for .htaccess

我想重写我的网址:

localhost/users/045da557b7

localhost/users/index.html?userID=045da557b7

这是我的.htaccess文件

RewriteEngine On
RewriteRule ^/([0-9a-z]{10})/$ /index.html?userID=$1 [L]

但是浏览器还给我404。

我在httpd.conf中没有注释掉重写mod。 谢谢您的帮助。

您需要通过将此规则放在/users/.htaccess来使用适当的RewriteBase

RewriteEngine On
RewriteBase /users/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-z]+)/?$ index.html?userID=$1 [L,QSA,NC]
^/([0-9a-z]){10}/$
a                b
   cccccccc dddd

a - anchor pattern to start of string
b - anchor pattern to end of string
c - allow numbers and lower case alphabet
d - must have exactly 10 characters


users/045da557b7

16 characters  (past your limit of 10)
contains a / - not in your list of allowed characters

您基本上已经说过“最多允许10个0-9a-z字符”,然后传入17个字符,并包含不允许的字符。 因此,您的整个模式将拒绝匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM