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 用问号和其他字符重定向url_.htaccess_Redirect - Fatal编程技术网

.htaccess 用问号和其他字符重定向url

.htaccess 用问号和其他字符重定向url,.htaccess,redirect,.htaccess,Redirect,如何使用htaccess文件将此url重定向到www.example.com used-machinery/en/other/used-machinery-item?000172:compost-turner 这样行吗 RewriteRule ^used-machinery/en/other/used-machinery-item?000172:compost-turner?$ http://www.example.com/ [R=301,L] RewriteRule ^(.*)$ inde

如何使用htaccess文件将此url重定向到www.example.com

used-machinery/en/other/used-machinery-item?000172:compost-turner
这样行吗

RewriteRule ^used-machinery/en/other/used-machinery-item?000172:compost-turner?$ http://www.example.com/ [R=301,L]

RewriteRule ^(.*)$ index.php/$1 [L]

会吗?导致旧url中出现问题?

问号应表示查询字符串,因此您必须设置写入条件以检测查询字符串。这应该行得通

RewriteEngine On
ReWriteCond %{REQUEST_URI} ^/used-machinery/en/other/used-machinery-item$
ReWriteCond %{QUERY_STRING} ^000172:compost-turner$
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]

RewriteRule ^(.*)$ index.php/$1 [L]
编辑:

对于大量URL,您可以使用“或”标志,甚至可以在服务器端尝试一些东西。这将是一个痛苦,但我不知道有任何其他解决方案与大量的链接

RewriteEngine On

# %{THE_REQUEST} format as follows
# GET /used-machinery/en/other/used-machinery-item?000172:compost-turner HTTP/1.1
# important notes: 
#     escape ? with( \?)
#     space after url (\ )
#     each line has [NC,OR] flags for case insensitive and checks this condition or the next
#     last Cond line does not have the OR flag

ReWriteCond %{THE_REQUEST} ^.+\ /used-machinery/en/other/used-machinery-item\?000172:compost-turner\ .*$ [NC,OR]
ReWriteCond %{THE_REQUEST} ^.+\ /anoterURL\?querystring\ .*$ [NC,OR]
ReWriteCond %{THE_REQUEST} ^.+\ /lastURL\?with-no-OR-at-end\ .*$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]

RewriteRule ^(.*)$ index.php/$1 [L]
如果您希望进行大规模编辑,我建议使用

  • 粘贴所有链接,每行一个链接
  • 关闭自动换行
  • 选择一个?在URL中
  • 在菜单中,查找>快速查找全部(选择页面上的全部)
  • 按左光标箭头
    • 键入\
  • 按结束键转到所有行的末尾
    • 键入\.*$[NC,或]
  • 按Home键转到所有行的开头
    • 键入ReWriteCond%{THE_REQUEST}^.+\
  • 编辑最后一行以删除,或

您可以在
文档\u ROOT/.htaccess
文件中使用此代码:

RewriteEngine On

RewriteCond %{QUERY_STRING} 000172:compost-turner [NC]
RewriteRule ^used-machinery/en/other/used-machinery-item/?$ /? [R=301,L]

RewriteRule ^((?!index\.php/).*)$ index.php/$1 [L,NC]

您想使用此规则重写哪些示例URL?另外,你想在浏览器中更改URL还是只想静默重写。如果这更容易理解,我更新了我的问题。如果我有多个此类URL实例,我会为每个实例创建一个查询字符串吗?似乎有很多工作要做?到了你想要匹配的模式。如果查询字符串不重要,则可以省略查看查询字符串的ReWriteCond行。如果需要的话,那么我们必须看看它应该匹配什么样的模式。抱歉,我只是想告诉你我在处理什么!检查上面的编辑。我不认为有一个简单的方法,如果我需要每个url重定向到不同的url,而不仅仅是。例如/used machines/en/other/used machines item\?000172:堆肥机\重定向到,/news/news item?open-days-a-just-success \重定向到等