[英]url rewrite not working .htaccess
我正在尝试使用htaccess重写url,并且在这里尝试了其他问题的答案,但是似乎没有任何作用,我仍然可以得到原始的url。 这就是我所拥有的:
http://localhost/inbox.php?pg=2
我想要
http://localhost/inbox/2
我已经有一条规则,如下所述,删除了.htaccess中的.php扩展名,并添加了最后一行
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
RewriteRule /(.*)$ /inbox.php?pg=$1//added this
您的问题是将最后一行之前的行定义为最后一行,因此您的规则必须在该RewriteConditions之上。 最好使用以下规则集:
RewriteRule ^/?inbox/(\d+)$ /inbox.php?pg=$1 [QSD,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
我添加了您错过的所需前缀,并强制要求在该前缀之后添加数字(至少一个)。
Apache重写引擎主要用于将动态url(例如http://localhost/inbox.php?pg=2
转换为静态且用户友好的url的http://localhost/inbox/2
RewriteEngine on
RewriteRule ^inbox/([^/.]+)/?$ /inbox.php?pg=$1 [L]
号召性用语: RewriteRule
模式: ^ inbox /([[^/.]+)/?$
重写: /inbox.php?pg=$1
命令标志: [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.