我试图通过编辑web root(public_html)目录下的.htaccess文件,从我的网站的url中删除.html扩展名。我的服务器是bluehost。
问题是我在.htaccess文件中的先前设置已经用于将主域重定向到子目录。
脚本如下。还有我在网上找到的用于从网址隐藏扩展名的脚本。(脚本不起作用)如果有人可以帮我解决问题,那将是非常好的。谢谢。
# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?qinglish.ca$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/qinglish_ca/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /qinglish_ca/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?qinglish.ca$
RewriteRule ^(/)?$ qinglish_ca/index.html [L]
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
答案 0 :(得分:3)
您需要使用这些规则来删除所有网址的.html
个扩展名,而不是您的上一条规则:
## hide .html extension
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# To internally forward /dir/file to /dir/file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]
将它们放在您有当前规则的同一位置,以添加.html
扩展名。