mod_rewrite: 完全 URL 不匹配但不完全匹配
mod_rewrite: Exact URL not matching but matches non exact
我在 .htaccess 文件中使用 mod_rewrite 重定向到另一个域时遇到问题。
这是我拥有的:
RewriteCond %{HTTP_HOST} ^www.somedomain.com/events_detail/an-event [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory/8559 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^www.somedomain.com [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory [L,R=301,NC]
出于某种原因 www.somedomain.com/events_detail/an-event
我被重定向到 http://otherdomain.com/directory
而不是 http://otherdomain.com/directory/8559
在测试仪上测试我的 .htaccess 时,它表明它不符合第一个条件但符合第二个条件。我已经尝试删除 L 选项,删除前向 ^ 没有成功。
谢谢
据我所知,HTTP_HOST 仅包含主机名(例如 www.somedomain.com) ,而不是完整的 url。您是否尝试过使用 REQUEST_URI 或 SCRIPT_FILENAME?
RewriteCond %{HTTP_HOST} ^www.somedomain.com$ [NC]
RewriteCond %{THE_REQUEST} /an-Event [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory/8559 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^www.somedomain.com$ [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory [L,R=301,NC]
我在 .htaccess 文件中使用 mod_rewrite 重定向到另一个域时遇到问题。
这是我拥有的:
RewriteCond %{HTTP_HOST} ^www.somedomain.com/events_detail/an-event [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory/8559 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^www.somedomain.com [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory [L,R=301,NC]
出于某种原因 www.somedomain.com/events_detail/an-event
我被重定向到 http://otherdomain.com/directory
而不是 http://otherdomain.com/directory/8559
在测试仪上测试我的 .htaccess 时,它表明它不符合第一个条件但符合第二个条件。我已经尝试删除 L 选项,删除前向 ^ 没有成功。
谢谢
据我所知,HTTP_HOST 仅包含主机名(例如 www.somedomain.com) ,而不是完整的 url。您是否尝试过使用 REQUEST_URI 或 SCRIPT_FILENAME?
RewriteCond %{HTTP_HOST} ^www.somedomain.com$ [NC]
RewriteCond %{THE_REQUEST} /an-Event [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory/8559 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^www.somedomain.com$ [NC]
RewriteRule ^(.*)$ http://otherdomain.com/directory [L,R=301,NC]