我正在尝试为我的网站网址创建.htaccess
脚本,但该网页无法加载... Not Found
The requested URL /Site/users/yax was not found on this server.
我希望<a href = 'http://localhost/Site/users/user.php?user=username'>View User</a>
出现
像这样:点击http://localhost/Site/users/name
但页面无法加载。
Apache代码:
RewriteEngine on
RewriteBase /Site/users/
RewriteCond %{THE_REQUEST} /users\.php\?user=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z_]+)$ users.php?user=$1 [L]
提前谢谢。
答案 0 :(得分:1)
将规则更改为:
RewriteEngine on
RewriteBase /Site/users/
RewriteCond %{THE_REQUEST} /users\.php\?user=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^users/([a-zA-Z_]+)$ users.php?user=$1 [L]
如果htaccess文件位于/Site/
文件夹中,则“users”将成为重写规则与匹配的URI的一部分,无论您将重写基础设置为
另外,您应该将链接更改为http://localhost/Site/users/name
,而不是每次都添加额外的往返重定向。
答案 1 :(得分:1)
试试这段代码:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /Site/
RewriteCond %{THE_REQUEST} /(users)/user\.php\?user=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(users)/(\w+)/?$ $1/user.php?user=$2 [L,QSA]
答案 2 :(得分:0)
假设/Site/users/user.php
是真实文件,并且在其URI中接受user = name ,
您的HTML:
<a href="http://localhost/Site/users/name">View User</a>
/ htaccess的:
RewriteEngine on
RewriteRule ^Site/users/(.*)$ /Site/users/user.php?user=$1