[英]Can't rewrite php url using htaccess
This will be a niche question but I am having trouble rewriting my url. 这将是一个小众问题,但我无法重写自己的网址。 I am trying to rewrite from /view.php?user=Alex0111 to view/Alex0111.
我正在尝试从/view.php?user=Alex0111重写为view / Alex0111。 I also have a second get variable of /view.php?user=Alex0111&id=5 which I want to be view/Alex0111/5 Here are the contents of my .htaccess file
我还有第二个get变量/view.php?user=Alex0111&id=5我想成为view / Alex0111 / 5这是我的.htaccess文件的内容
DirectoryIndex Home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^view/([0-9A-Za-z]+) view.php?user=$1 [NC,L] #doesn't work causes internal error
I've checked this line of code multiple times to the tutorial I am following but I am missing the mark on something. 我已经在我正在关注的教程中多次检查了这一行代码,但是我在某些东西上没有标记。
Replace both of your rewrite rules with: 将两个重写规则替换为:
RewriteRule ^view/(.+)/(.+) view.php?user=$1&id=$2 [NC,END,QSA]
Your first rewrite rule will interfere because it will rewrite the path as Markus mentioned in comments. 您的第一个重写规则将产生干扰,因为它将按照注释中提到的Markus来重写路径。
The [END]
flag will throw an error if you have an old Apache version. 如果您使用的是旧版本的Apache,则
[END]
标志将引发错误。 In that case, use the [L]
在这种情况下,请使用
[L]
The [QSA]
flag tells the server to add any additional query parameters that the user sent. [QSA]
标志告诉服务器添加用户发送的任何其他查询参数。 eg: view/Alex01/5? 例如: view / Alex01 / 5? param=value
参数=值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.