Php .htaccess 301重定向URI的子字符串-it';s在URI的末尾追加$GET[';变量';]
我刚刚建立了一个新网站,并将其中一个类别拼写为Php .htaccess 301重定向URI的子字符串-it';s在URI的末尾追加$GET[';变量';],php,.htaccess,mod-rewrite,redirect,Php,.htaccess,Mod Rewrite,Redirect,我刚刚建立了一个新网站,并将其中一个类别拼写为autimobiles,而不是automobiles——我知道这很神奇。我为任何包含子字符串autimobiles的URL设置了.htaccess301重定向,以重定向到automobiles。因此,URI/autimobiles/BMW pictures应该重定向到/automobiles/BMW pictures。然而,这就是正在发生的事情 这个 http://imageocd.com/autimobiles/hupmobile-touring-
autimobiles
,而不是automobiles
——我知道这很神奇。我为任何包含子字符串autimobiles
的URL设置了.htaccess
301重定向,以重定向到automobiles
。因此,URI/autimobiles/BMW pictures
应该重定向到/automobiles/BMW pictures
。然而,这就是正在发生的事情
这个
http://imageocd.com/autimobiles/hupmobile-touring-pictures-and-wallpapers
正在重定向到此
http://imageocd.com/automobiles/hupmobile-touring-pictures-and-wallpapers?one=autimobiles&two=hupmobile-浏览图片和壁纸
下面是我如何设置.htaccess
的
我有两个$\u GET['']
变量名为$\u GET['one']
&&$\u GET['two']
,用于mod rewrite。重定向时,这两个变量在URI中显示为$\u GET['']
变量。我想从URI中删除?one=autimobiles&two=hupmobile旅游图片和壁纸
这是我的.htaccess
# Important line HERE
RedirectMatch permanent autimobiles(.*) http://imageocd/automobiles$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+) index.php?one=$1&two=$2 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+) index.php?one=$1 [NC,L]
在.htaccess
中更新
RewriteCond %{QUERY_STRING} ^autimobiles(.*)$
RewriteRule ^autimobiles(.*)$ http://imageocd.com/automobiles$1 [R=301,L]
#load-data (2) -- index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+) index.php?one=$1&two=$2 [NC,L]
#load-data (1) -- index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+) index.php?one=$1 [NC,L]
如果我正确理解你的问题。。。此代码:
RewriteEngine On
RewriteRule ^autimobiles/(.*)$ http://temp/automobiles/$1 [R=301,L]
从/autimobiles/BMW pictures
重定向到/automobiles/BMW pictures
编辑:
您写道:How to remove“?one=autimobiles&two=hupmobile touring pictures and wallpaps”从URL末尾。重定向可以工作,但它会在URL上附加bot get变量
如果你只想删除汽车路径上的标签。。因此,让这句话成为你的台词:
RewriteRule ^autimobiles(.*)$ http://imageocd.com/automobiles$1 [R=301,L]
#load-data (2) -- index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !^automobiles(.*)$
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+) index.php?one=$1&two=$2 [NC,L]
#load-data (1) -- index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !^automobiles(.*)$
RewriteRule ^([a-zA-Z0-9-]+) index.php?one=$1 [NC,L]
如何从URL末尾删除“?一=自动移动图片&二=hupmobile巡回图片和墙纸”。重定向是有效的,但它在URL上附加了bot get变量。这是正确的想法,但它不起作用。它并没有将“/autimobiles/BMW pictures”重定向到“/automobiles/BMW pictures”,而且,我将“auautimobiles”替换为“automobiles”,将“temp”替换为“sites name”,注意,这是唯一一行进行301重定向的。删除.htaccess
文件中的其他命令,并仅插入此行。也http://temp/
替换为您的域名。我在问题中更新了我的.htaccess,与更新一样;不行。但是,对于mod-rewrite,我需要另外两条规则。当你的代码在两个块以下时,加载数据-他们添加了这个GET
参数!因此,如果你删除这行或用#
注释,一切都会正常工作!试试看。