简体   繁体   中英

Whats wrong with this RewriteRule for .htaccess

I want to rewrite my url:

localhost/users/045da557b7

to

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

here is my .htaccess

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

But the browser gives me 404 back.

I have the rewrite mod uncommented in the httpd.conf. Thank you for your help.

You need to use proper RewriteBase by placing this rule in /users/.htaccess :

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

You've basically said "allow at most 10 charccters of 0-9a-z", then passed in 17 characters and include characters that aren't allowed. So your entire pattern will refuse to match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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