我刚刚用html创建了一个网站,我试图让网址看起来像这样:www.domainname.com/hello而不是www.domainname.com/hello.html
我发现了一个名为friendlyurls的生成器,但只有主页重定向才会起作用,迫使www.domainname.com而不仅仅是domainname.com
我试图修改代码但没有运气可以有人对此有所了解吗?
RewriteEngine On
RewriteBase /
# Force search engines to use www.domain.co.uk
RewriteCond %{HTTP_HOST} !^www\.domain\.co\.uk$
RewriteRule ^(.*) http://www.domain.co.uk/$1 [R=301,L]
# Specify search friendly URLs
RewriteRule ^/packages$ /packages.html [L]
答案 0 :(得分:0)
您可以在根目录中使用这些规则.htaccess:
RewriteEngine On
RewriteBase /
# Force search engines to use www.domain.co.uk
RewriteCond %{HTTP_HOST} ^domain\.co\.uk$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.html[\s?] [NC]
RewriteRule ^ /%1%2 [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]