htaccess mod_rewrite - 重写参数,无需任何扩展名

时间:2018-02-20 20:51:34

标签: .htaccess mod-rewrite

我在example.com/go/

中得到了这个htaccess
RewriteEngine On

RewriteRule ^([^/]*)\.html$ /go/?there=$1 [L]

因此example.com/go/ttt.html变为example.com/go/?there=ttt

但我不想要任何扩展程序,我想删除.html,所以我尝试了:

RewriteEngine On

RewriteRule ^([^/]*)$ /go/?there=$1 [L]

但它不起作用,example.com/go/ttt提供内部服务器错误

如何正确做到?

1 个答案:

答案 0 :(得分:0)

尝试添加此行:

RewriteCond %{REQUEST_FILENAME}.html -f 

所以,代码将是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^([^/]*)$ /go/?there=$1 [L]

然后测试example.com/go/ttt

UPDTAE:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.*)$ /go/$1.html [L]
RewriteRule ^([^/]*)\.html$ /go/?there=$1 [L]