301 重定向有关动态 URL 和多个 ID 的帮助
我刚刚对 www.wildchildclothes.com 进行了重新设计,它具有新的 URL 结构。旧网站在 Zen Cart 上运行,并且 URL 结构很糟糕。以下是我想要重定向的一些示例:
旧:www.wildchildclothes.com/page.html?chapter=1&id=21 新:www.wildchildclothes.com
和...
旧:www.wildchildclothes.com/index.php?main_page=faq_info&fcPath=0&faqs_id=13 新:www.wildchildclothes.com/customer-service.html
以下是我的 .htaccess 中实现此目的的内容:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^([^&]*&)*chapter=1(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*id=21(&|$)
RewriteRule ^page\.html http://www.wildchildclothes.com? [L,R=301]
RewriteCond %{QUERY_STRING} ^([^&]*&)*main_page=faq_info(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*fcPath=0(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*faqs_id=13(&|$)
RewriteRule ^index\.php$ http://www.wildchildclothes.com/customer-service.html? [L,R=301]
但这根本不起作用 - 我只会被发送到我的 404 页面,而不是开始重定向。任何人都可以透露一些信息吗?完整的 .htaccess 发布在下面。
非常感谢, 约拿
I just did a redesign for www.wildchildclothes.com which has a new URL structure. The old site ran on Zen Cart and had a bad URL structure. Here are some examples of what I want to redirect from:
OLD: www.wildchildclothes.com/page.html?chapter=1&id=21
NEW: www.wildchildclothes.com
and...
OLD: www.wildchildclothes.com/index.php?main_page=faq_info&fcPath=0&faqs_id=13
NEW: www.wildchildclothes.com/customer-service.html
Here is what's in my .htaccess to achieve this:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^([^&]*&)*chapter=1(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*id=21(&|$)
RewriteRule ^page\.html http://www.wildchildclothes.com? [L,R=301]
RewriteCond %{QUERY_STRING} ^([^&]*&)*main_page=faq_info(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*fcPath=0(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*faqs_id=13(&|$)
RewriteRule ^index\.php$ http://www.wildchildclothes.com/customer-service.html? [L,R=301]
But this doesn't work at all - I only get sent to my 404 page instead of begin redirected. Can anyone shed some light? The full .htaccess is posted below.
Thanks much,
Jonah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
上述解决方案都不适合我,但这确实有效:
将 www.wildchildclothes.com/page.html?chapter=1&id=21 重定向到 www.wildchildclothes.com:
重定向 www.wildchildclothes.com/index.php ?main_page=document_product_info&products_id=280 至 www.wildchildclothes.com:
将 www.wildchildclothes.com/index.php?main_page=faq_info&fcPath=0&faqs_id=9 重定向至 www.wildchildclothes.com/customer-service.html :
我确信有更好的方法可以做到这一点,但这对我有用,而 .htaccess 只是让我头疼,所以我不再进一步挖掘。
我希望这对其他人有帮助!
None of the above solutions worked for me, but this does:
To redirect www.wildchildclothes.com/page.html?chapter=1&id=21 to www.wildchildclothes.com:
To redirect www.wildchildclothes.com/index.php?main_page=document_product_info&products_id=280 to www.wildchildclothes.com:
To redirect www.wildchildclothes.com/index.php?main_page=faq_info&fcPath=0&faqs_id=9 to www.wildchildclothes.com/customer-service.html:
I'm sure there are better ways to do this but this works for me and .htaccess just gives me a headache so I'm not digging any further.
I hope this helps someone else out there!
如果您使用 PHP 进行重定向,会更容易、更好。例如,您可以将此类请求重写为 PHP 脚本,该脚本分析 URL 参数并重定向到正确的页面。也许是这样的:
以及相应的
RewriteRule
:It would be easier and far better if you use PHP for the redirect. You could, for example, rewrite such requests to a PHP script that analyzes the URL arguments and redirects to the correct page. Maybe something like this:
And the corresponding
RewriteRule
:您希望在查询参数中允许使用多个字符。将
[^&]&
更改为[^&]*&
:You want to allow more than one character in the query parameters. Change
[^&]&
to[^&]*&
: