.htaccess生成友好的url';s

.htaccess生成友好的url';s,.htaccess,seo,.htaccess,Seo,我有一个网站www.example.com/index.php?q=registration我想把它重定向到www.example.com/registration 这个代码似乎不起作用,但我不知道为什么 RewriteEngine On RewriteRule ^([^/]*)\.html$ /index.php?q=$1 [L] 有人能帮我吗?这是因为您的重写规则需要.html。将浏览器指向 www.example.com/registration.html 应与您的htaccess一

我有一个网站www.example.com/index.php?q=registration我想把它重定向到www.example.com/registration

这个代码似乎不起作用,但我不知道为什么

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /index.php?q=$1 [L]

有人能帮我吗?

这是因为您的重写规则需要.html。将浏览器指向

www.example.com/registration.html 
应与您的htaccess一起工作;另一条规则是:

RewriteRule ^([^/]*)/$ /index.php?q=$1 [L,QSA]
最好将QSA标志添加到两个规则中,以确保附加任何其他查询字符串参数

最后,您的.htaccess应该类似于:

RewriteEngine On
RewriteRule \.(jpg|png|gif|php)$  - [L]
RewriteRule ^([^/]*)\.html$ /index.php?q=$1 [L,QSA]
RewriteRule ^([^/]*)/$ /index.php?q=$1 [L,QSA]
RewriteRule ^([^a-z0-9_]+)*$ /index.php?q=$1 [L,QSA]
试试这个

RewriteEngine On
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteRule ^([^/]*)(.*)$ /$1[L,QSA]

哦,我错了,但如果我写www.example.com/registration,它会显示404错误,它只适用于registration.htmlwrite www.example.com/registration/更新答案以帮助您解决更多问题。。。阅读常规表达仍然没有成功,但Ajeesh的解决方案有效。无论如何,谢谢你的帮助。