Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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 使用htaccess修复url错误_.htaccess - Fatal编程技术网

.htaccess 使用htaccess修复url错误

.htaccess 使用htaccess修复url错误,.htaccess,.htaccess,因此,启动了一个网站,并犯了一个错误的链接,并没有正确的结构。由于这些链接中有相当一部分是在谷歌上找到的,我需要在不影响正确链接的情况下永久地重定向错误的链接,并且不知道如何正确地做 我的链接应该是这样的:/compare/itemname.html 但由于错误,他们在谷歌上的形象是这样的: /比较/itemname(不含.html部分) 这只是因为我在创建链接时错过了.html 现在已经动态地修复了这个位 这在我的htaccess中,工作正常: RewriteCond %{THE_REQUES

因此,启动了一个网站,并犯了一个错误的链接,并没有正确的结构。由于这些链接中有相当一部分是在谷歌上找到的,我需要在不影响正确链接的情况下永久地重定向错误的链接,并且不知道如何正确地做

我的链接应该是这样的:/compare/itemname.html

但由于错误,他们在谷歌上的形象是这样的: /比较/itemname(不含.html部分)

这只是因为我在创建链接时错过了.html 现在已经动态地修复了这个位

这在我的htaccess中,工作正常:

RewriteCond %{THE_REQUEST} \ /+index\.php\?keyword=([^&\ ]+)
RewriteRule ^ /compare/%1.html? [L,R]
RewriteRule ^compare/([^/]*)\.html$ /index.php?keyword=$1 [NC,L]
那么如何将/compare/itemname更改为/compare/itemname.html呢 itemname可以更改的位置-不会在 .htaccess

或者在这个阶段仅仅做一个301重定向再怎么做更好 我能挑出缺少.html的URL项目名吗


感谢您的帮助

在/compare/dir中尝试此.htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ http://www.example.com/compare/$1\.html [L,R=301]

您可以添加新的重定向规则以添加
.html

RewriteCond %{THE_REQUEST} \ /+index\.php\?keyword=([^&\ ]+)
RewriteRule ^ /compare/%1.html? [L,R]

RewriteRule ^(compare/[^.]+)/?$ /$1.html [NC,L,R]

RewriteRule ^compare/([^.]+)\.html$ /index.php?keyword=$1 [NC,L,QSA]

有多少个链接?从我所能看到的谷歌上大约50 x两个站点的链接是不正确的。其他的都很好-这只是一个额外的链接,我错过了改变。它们都有不同的itemname您是否碰巧有一个.htaccess加上尾部斜杠?您可以在compare目录中将其重写为ammend a.html。让我去找到我的并发布它。不,这是一个硬编码的链接,我犯了一个错误,遗漏了.html位。虽然没有比较目录,但它只是由上面发布的htaccess位执行的重写。谢谢,但是没有比较firecotory,它只是由上面的htaccess代码位执行的重写创建目录,然后看看它是否工作。或者试试另一个。htaccess Answer已经使用了这个解决方案,但是没有使用QSA,因为我不确定它是否需要,并且在目前我所能看到的情况下没有它也可以工作。谢谢你的帮助!是的,QSA不是必须的,但我把它放在那里,以防你想保留以前的任何查询。