如何将fromxistant文件夹中的url重写为mod_rewrite中的文件

时间:2016-03-08 10:08:34

标签: apache .htaccess mod-rewrite

我想重写两个

www.mywebsite.com/example www.mywebsite.com/example /

mywebsite.com/example.shtml

我在.htaccess中使用以下规则:

RewriteEngine On
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.shtml -f
RewriteRule ^(.*)$ $1.shtml

然而,这不起作用,我得到内部服务器错误。如果我只有以下规则:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.shtml -f
RewriteRule ^(.*)$ $1.shtml

然后 www.mywebsite.com/example 重新写入 mywebsite.com/example.shtml ,但是当我请求www.mywebsite时出现内部服务器错误的.com /示例/。

请告知

1 个答案:

答案 0 :(得分:0)

请尝试以下规则:

Options -MultiViews
RewriteEngine On

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [NE,R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.shtml -f
RewriteRule ^(.+?)/?$ $1.shtml [L]

在测试此更改之前,请完全清除浏览器缓存。

相关问题