2015-11-04 133 views
0

感谢您的帮助。我一直试图解决这个问题一个小时。Htaccess删除点的重写规则

我有这样的.htaccess将改写/file.html的脚本,但决定删除扩展,它原来是这样的:

RewriteEngine On 
#RewriteRule ^([^/]*)\.html$ /?file=$1 [L] 
RewriteRule ^([^\.]+)$ /index.php?file=$1 [NC,L] 

不过,现在我需要它包含文件名也行点(即/file.with.dots),但该规则不允许它。

这一个适用于以点文件,但以html

#RewriteRule ^(.*)\.html$ /index.php?file=$1 [NC] 

这让我的内部服务器错误

RewriteRule ^([^/]+)$ /index.php?file=$1 [NC,L] 

回答

0

你可能只是这样做的结局。

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)/?$ /index.php?file=$1 [NC,L] 

让我知道结果。

+0

谢谢,杰克,为您的快速回复,但带点的文件名不工作。在我遇到Forbidden错误之前,现在我已经得到了404。其余的人工作正常。 – Elijah

+0

类似site.com/aname.com的网址将无法使用 – Elijah

+0

您是否尝试使用上述规则,除了此重写规则:RewriteRule ^(。*)/?$ /index.php?file=$1 [NC,L] '但是它应该工作。 –