htaccess 重写仅部分有效
我正在使用 htaccess 规则重写我的 URL 之一,但它并没有按照我想要的方式工作。
当我将浏览器指向新的动态创建的 URL 时,我的 htaccess 规则会将请求切换到旧 URL(理应如此),以便显示旧 URL 的内容。尽管如此,新网址现在也已更改为旧网址。
即我希望我的浏览器显示 itemdetails.php?detailed=47 的页面信息,但看起来好像正在访问 www.mysite.com/blue-item-e47
我的重写规则是: RewriteRule ^.*-e([0 -9]+)$ /itemdetails.php?detailed=$1 [R]
当前发生的情况的示例:
我将浏览器指向:www.mysite.com/blue-item-e47
我的浏览器将 URL 切换为:itemdetails.php?detailed=47 并正确显示页面信息。尽管如此,我希望 URL 为 www.mysite.com/blue-item-e47
非常感谢
David
I am using a htaccess rule to rewrite one of my URL’s but it is not working quite how I want it to.
When I point my browser to my new dynamically created URL my htaccess rule switches the request to the old URL (as it should) so the content of the old URL is displayed. Despite this, the new url has also now changed to the old one.
i.e. I want my browser to display the page information for itemdetails.php?detailed=47 but appear as if it is accessing www.mysite.com/blue-item-e47
My rewrite rule is: RewriteRule ^.*-e([0-9]+)$ /itemdetails.php?detailed=$1 [R]
An example of what is happening at the minute:
I point my browser to: www.mysite.com/blue-item-e47
My browser switches URL to: itemdetails.php?detailed=47 and displays the page information correctly. Despite this I want the URL to be www.mysite.com/blue-item-e47
Many thanks
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但 URL 重写器就是这么做的。它基本上是对你的浏览器说:“你要求这个,现在要求我提供这个,因为这就是现在的位置”,向它发送了一个 302 页面已移动。
如果您不想更改 URL,则不应重写它,最好在站点代码中进行重写
But the URL rewriter does just that. It basically says to your browser, "You asked for this, now asked me for this as this is where it is now" having sent it a 302 page has moved.
If you didnt want the URL to change, you shouldnt be rewriting it, you would do better to do it within the code of your site