htaccess正则表达式,文件名中有两个句点

时间:2011-05-10 06:18:01

标签: regex .htaccess

我有这个当前表达式,site.com/index.phpsite.com/index

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]

我需要让它接受包含两个句点的文件名,例如site.com/core.index.phpsite.com/core.index

任何帮助将不胜感激!

3 个答案:

答案 0 :(得分:1)

正则表达式^(.*)(?<!\.php)$匹配每个不以“.php”结尾的地址,所以

RewriteRule ^(.*)(?<!\.php)$ $1.php [NC,L]

可行。不过,我对RewriteRule并不熟悉。

答案 1 :(得分:0)

使用此正则表达式^[\w\d]*\.[\w\d]*\/[\w\d]*\.[\w\d]* enter image description here

答案 2 :(得分:0)

还提供更简单的解决方案:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f   # We don`t have such file (includes !-d)
RewriteRule ^(.*)$ $1.php [NC,L]     # Just add .php to the end