.htaccess 重写规则未正确重定向
我希望能够使用重写规则重定向打开链接的任何人:.htaccess 重写规则未正确重定向,.htaccess,.htaccess,我希望能够使用重写规则重定向打开链接的任何人: domain.com/name 到 最好的方法是什么 我试图发布我编写的htaccess代码,但stackoverflow一直说它不符合标准,所以我删除了它。 提前感谢这样的东西就可以了: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI
domain.com/name
到
最好的方法是什么
我试图发布我编写的htaccess代码,但stackoverflow一直说它不符合标准,所以我删除了它。
提前感谢这样的东西就可以了:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)/? [NC]
RewriteRule .* index.php?username=%1 [L,QSA]
它将无声地映射
http://domain.com/name
到
http://domain.com/index.php?username=name
要使其正常工作,
/name
必须是传入URL路径中的第一个目录。您的意思是“index.php?username=name”是。修正了,对不起。实际上是这样的:index.php?a=profile&u=johndemight最好在重写规则上使用QSA(查询字符串附加)选项,以便传递其他GET参数。@Wivlaro同意。谢谢我没有把它包括在内,因为这个问题看起来很具体,但它并不伤人。再次感谢。现在,如果我转到domain.com,则网站会中断并显示:no username found返回一个错误,显示no username found,好像它没有通过%1。我必须将其更改为$1吗?不需要。请将您在浏览器地址栏中输入的完整URL复制粘贴到注释中,以了解问题所在。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)/? [NC]
RewriteRule .* index.php?username=%1 [L,QSA]