Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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
Php htaccess查询字符串删除_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php htaccess查询字符串删除

Php htaccess查询字符串删除,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有以下网址: http://www.efilmsworld.com/film.php?url=blended-film-2014 我在.htaccess中使用了以下内容: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]*)\.html$ /film.php?url=$1 [L,QSA] 将我的ur

我有以下网址:

http://www.efilmsworld.com/film.php?url=blended-film-2014
我在
.htaccess
中使用了以下内容:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /film.php?url=$1 [L,QSA]
将我的url重写为:

http://www.efilmsworld.com/blended-film-2014.html
在这之前一切都很好。但问题是我有两个工作URL,它复制了不好的内容:

efilmsworld.com/film.php?url=blended-film-2014
efilmsworld.com/blended-film-2014.html
因此,我需要删除查询字符串url,例如:

efilmsworld.com/film.php?url=blended-film-2014
添加

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /film\.php\?url=(.*)\ HTTP
RewriteRule ^ /%2.html? [R=301,L]
到你的htaccess将解决这个问题

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /film\.php\?url=(.*)\ HTTP
RewriteRule ^ /%2.html? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /film.php?url=$1 [L,QSA]
将会发生的是

  • 如果输入了
    efilmsworld.com/film.php?url=blended-film-2014
    ,则url将被重写为
    efilmsworld.com/blended-film-2014.html
    ,然后以静默方式重写(即地址栏中的url不会更改)回
    efilmsworld.com/film.php?url=blended-film-2014
    ,因此仍然显示内容
  • 如果输入了
    efilmsworld.com/blended-film-2014.html
    ,它将被默默地重写为
    efilmsworld.com/film.php?url=blended-film-2014
    (您已经在执行此操作了)
  • [R=301]
    标志告诉浏览器(和搜索引擎)url已更改,现在可以在
    sometitle.html
    中找到。该页面现在只显示一次,因此不再重复内容
  • 编辑:根据评论请求

    RewriteCond %{THE_REQUEST} ^(GET|POST)\ /video\.php\?url=(.*)\ HTTP
    RewriteRule ^ /video/%2.html? [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^video/([^/]*)\.html$ /video.php?url=$1 [L,QSA]
    

    好的,您可以添加另一个RewriteRule,使外部重定向到“正确”版本,在它之前使用RewriteCond检查查询字符串…但是如果“double content”形成搜索引擎的观点是您主要关心的问题,那么在HTML文档中指定一个标准URL就足够了。感谢CBroe,请详细说明,因为我对htaccess非常陌生,对RewriteEngine的了解有限。我还有一个问题与我将“”改写为“”有关请让我知道我如何能结合为这同样的“电影页”感谢伟大的帮助,现在一切都很好。