删除扩展名为.html的网址 [英] remove .html extension from url
问题描述
我想编辑在网站根目录(的public_html)目录下的.htaccess文件删除.html扩展名的网址为我的网站。我的服务器是BlueHost的。
现在的问题是,我有previous设置中已经.htaccess文件的重定向主域到子目录的目的。
该脚本如下。另外随着剧本我在网上找到了隐藏扩展名的URL。(该脚本不工作),这将是非常好的,如果有人可以帮助我的问题。谢谢。
#使用PHP5.4单php.ini中的默认
AddHandler的应用程序/ x-的httpd-php54s的.php
#BlueHost.com
#htaccess的主要领域为子目录重定向
#不要更改此行。
RewriteEngine叙述上
#更改example.com是你的主要领域。
的RewriteCond%{HTTP_HOST} ^(WWW)?qinglish.ca $
#改变子目录是你会用你的主域的目录。
的RewriteCond%{REQUEST_URI}!^ / qinglish_ca /
#不要更改以下两行。
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
#改变子目录是你会用你的主域的目录。
重写规则^(。*)$ / qinglish_ca / $ 1
#更改example.com再次成为你的主要领域。
#改变子目录是你将用你的主域名目录
#后跟/然后在主文件为您的网站的index.php,index.html的,等等。
的RewriteCond%{HTTP_HOST} ^(WWW)?qinglish.ca $
重写规则^(/)?$ qinglish_ca / index.html的[L]
选项-MultiViews
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ HTML!-f
重写规则^([^ \。] +)$ $ 1.HTML [NC,L]
而不是你的最后一条规则,你将需要这些规则来来回回删除的.html
扩展名的所有网址:
##隐藏.html扩展
#要外部重定向/dir/file.html到/目录/文件
的RewriteCond%{THE_REQUEST} \ S / +(。+?)\ HTML [\ S?] [NC]
重写规则^ /%1 [R = 302,L,NE]
#在内部前进/目录/文件/dir/file.html
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{DOCUMENT_ROOT} / $ 1 \ html的-f [NC]
重写规则^(。+?)/?$ /$1.html [L]
将它们放置在您拥有最新的规则,以增加的.html
扩展同一个地方。
I'm trying to remove the .html extension from url for my website by editing the .htaccess file under the web root(public_html) directory. My server is bluehost.
The problem is that I have previous settings in the .htaccess file already for the redirecting primary domain to a subdirectory purpose.
The script is below. Also with the script i found online for hiding the extension from url.(The script doesn't work) It will be really nice if someone can help me out with the problem. Thanks.
# 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]
Instead of your last rule you will need these rules to remove .html
extensions fro all URLs:
## 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]
Place them at same place where you have current rule to add .html
extension.
这篇关于删除扩展名为.html的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!