如何使用htaccess文件将此网址重定向到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]
会吗?导致旧网址出现问题?
答案 0 :(得分:1)
问号应该代表一个查询字符串,因此您必须编写一个条件来检测查询字符串。这应该工作
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]
编辑:
使用大量网址或网址,您可以使用" OR"标志或甚至可能在服务器端尝试一些东西。这将是一个痛苦,但我不知道任何其他解决方案与大量的链接。
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]
如果您希望进行批量修改,建议您使用Sublime Text
答案 1 :(得分:0)
您可以在DOCUMENT_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]