.htacces & RewriteRule:现在所有链接都已损坏(应用 RewriteRule 修改 URL 后)
应用 RewriteRule ^([^/]*)/$ /index.php?q=$1 [L]
后,现在您可以输入 mysite.com/aboutus/
以及 mysite.com/?p=aboutus
。现在又出现了一个问题: 如果您输入 mysite.com/aboutus/
,则页面和图片加载正常,但页面 mysite.com/aboutus/
上的链接将如下所示:mysite.com/aboutus/index.php?p=link1
而不是 mysite.com/index.php?p=link1
(也是 mysite.com/link1
> 会更好!)。 这个问题该如何解答呢?链接太多,无法手动替换。
PS 每个链接看起来都像 单击此处
,而不是像 http://mysite.com?p=link1
。
谢谢。
After RewriteRule ^([^/]*)/$ /index.php?q=$1 [L]
was applied, now you can type mysite.com/aboutus/
as well as mysite.com/?p=aboutus
. Now another problem appeared:
If you type mysite.com/aboutus/
, then the page and pictures load fine, but links on the page mysite.com/aboutus/
will look like: mysite.com/aboutus/index.php?p=link1
instead of mysite.com/index.php?p=link1
(also mysite.com/link1
would be even better!).
How to solve this question? There are too many links to replace them manually.
P.S. Every link looks like <a href="?p=link1" > click here </a>
and NOT like http://mysite.com?p=link1
.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以添加另一个 RewriteRule:
这将使您的链接有效但多余。您仍然会有诸如
http://mysite.com/path_1/index.php?p=link1
和http://mysite.com/path_2/index.php?p= 的链接link1
在您的页面中。You can add another RewriteRule:
This will make your links valid but redundant. You will still have links like
http://mysite.com/path_1/index.php?p=link1
andhttp://mysite.com/path_2/index.php?p=link1
in your pages..htaccess 不以任何方式负责您的软件如何链接到事物,它重写来自用户的传入 URL,而不是您的 HTML 文件。如果链接是相对于路径建立的,那么您最终会遇到您所描述的问题。
如果您是该软件的作者,您实际上别无选择,只能替换链接。如果您使用其他软件,它可能有一个搜索引擎友好的网址选项。
.htaccess is not in any way responsible for how your software links to things, it rewrites incoming urls from the user, not your HTML files. If the links are made relative to the path, then you end up with the problem you're describing.
If you're the author of the software you don't really have any choice but to replace the links. If you're using some other software it might have an option for search engine friendly urls.