Mod 重写 - 动态 $_GET 重写
无论如何,是否使用 ModRewrite 来实现以下目的:
初始 URL: http://example.com/page?value=测试
重写的网址:http://example.com/page/value/test
或
初始 URL:http://example.com/page?value=test&fruit=apple
重写 URL:http://example.com/page/value/test? Fruit=apple
我需要这个规则是动态的,因为我不知道它将用于哪些页面,而且我还需要在 PHP 中保留 $_GET 变量。
谢谢
Is there anyway using ModRewrite to achieve the following:
Initial URL: http://example.com/page?value=test
Rewirted URL: http://example.com/page/value/test
OR
Initial URL: http://example.com/page?value=test&fruit=apple
Rewirted URL: http://example.com/page/value/test?fruit=apple
I need this rule to be dynamic as I don't know all the pages it is going to be used for and I also need to retain the $_GET variables in PHP.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有问题的 URL 存储在数据库中,并且需要重写,直到可以更新内容以反映新的 URL 模式,那么这个问题就有意义了。为了澄清问题,这将被视为重定向而不是重写,从而改善搜索引擎优化。然后,正如上面的注释所指出的,可以重写 URL 来为 PHP 提供正确的 URL 参数。如果这正是 James 的意图,下面的配置将会有所帮助:
这很混乱,但我遇到过类似的情况,在内容可以更新之前,需要重定向数据库中存储的旧 URL。
希望这有帮助。
The question makes sense if the URLs in question are stored in the database, and need to be rewritten until the content can be updated to reflect the new URL pattern. Which, for clarification of the question, would be considered a redirect not rewrite, therefore improving SEO. Then, as the comments above point out, the URL could then be rewritten to provide PHP the correct URL parameters. If this what James intended, the config below will help out:
This is messy, but I've run into similar situations where redirecting old URLs stored in the database was necessary until content could be updated.
Hope this helps.