Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess,URL更改但正在加载内容_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

.htaccess,URL更改但正在加载内容

.htaccess,URL更改但正在加载内容,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我在.htaccess中遇到问题,我成功地重写了URL,但内容不再加载 下面是我的htaccess文件 我的目标是删除我所有的.html页面(该站点由.html静态页面组成)的扩展名。但是,我需要将.html URL重定向到新的URL,这样我的SEO就不会受到这些更改的影响 例如: 原件:www.example.co.uk/page.html 需要:www.example.co.uk/page/ 重要的是,原始URL重定向新URL的地址 Options +FollowSymLinks Rew

我在.htaccess中遇到问题,我成功地重写了URL,但内容不再加载

下面是我的htaccess文件

我的目标是删除我所有的.html页面(该站点由.html静态页面组成)的扩展名。但是,我需要将.html URL重定向到新的URL,这样我的SEO就不会受到这些更改的影响

例如:

  • 原件:www.example.co.uk/page.html
  • 需要:www.example.co.uk/page/
重要的是,原始URL重定向新URL的地址

Options +FollowSymLinks
RewriteEngine on

# REDIRECT yourdomain.com TO www.yourdomain.com
RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]

RewriteRule (.+)\.html?$ http://www.example.co.uk/$1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(([^/]*/)*[^/.]+)$ $1.html [L]
我试过上面的htaccess,也试过下面的变体,但都没有达到预期效果。任何帮助都将不胜感激

Options +FollowSymLinks
RewriteEngine on

# REDIRECT yourdomain.com TO www.yourdomain.com
RewriteCond %{HTTP_HOST} !^www.example.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]

RewriteRule (.+)\.html?$ http://www.example.co.uk/$1/ [R=301,L]

你需要改变两件事

  • 在重定向之后添加此选项,以防止重定向循环:

    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    
  • 将最后一条规则更改为:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/(.*?)/?$
    RewriteCond %{DOCUMENT_ROOT}/%1\.html -f
    RewriteRule ^ /%1.html [L]