如何使 rewriterule 添加锚点到 wordpress url 而不是“/”?
我是 .htaccess 新手,但我认为这是最好的方法。 我需要让 wordpress 将 url 中的“/”更改为“#”。结构如下: http://thewebsite/pageid/sub_pageid ,所需的效果将是 http://thewebsite/pagid#sub_pageid 。我尝试了一些在网上找到的规则,但每一条都失败了。我相信它是因为我应用了这些规则。我只有一个页面有子页面,并且它是唯一需要重写的页面。重定向后我希望 jquery 向下滚动到锚点。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /thewebsite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /thewebsite/index.php
</IfModule>
# END WordPress
我尝试过 RewriteRule ^page/ page# [NE] 但失败了。我尝试了很多其他方法,但没有效果。希望有人以前遇到过这个问题并且知道,或者可以解释我失败的原因。 谢谢!
I'm a .htaccess nOOb, but I think this is the best way to do it.
I need to make wordpress change the '/' into '#' in the url. The structure goes like:
http://thewebsite/pageid/sub_pageid and the desired effect would be http://thewebsite/pagid#sub_pageid . I've tried few rules I found on-line, but each one of them have failed. I believe its because I have those rules applied to it. There is only one page I have subpages for and it's the only one that needs rewriting. After the redirect I want jquery to scroll down to the anchor.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /thewebsite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /thewebsite/index.php
</IfModule>
# END WordPress
I've tried RewriteRule ^page/ page# [NE] but I've failed. I've tried many others, but no effect. Hope someone had this problem before and just knows, or can explain why I fail.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只是尝试为单个页面重写它,请尝试:
这应该是特定页面 ID 或字符串所需的全部内容。 NE 表示“noescape”,允许您重写井号 (#) 符号。
对于任何页面 ID:
If you are just trying to rewrite it for a single page, try:
That should be all you need for a specific page id or string. NE means 'noescape,' allowing you to rewrite the hash (#) symbol.
For any page id:
如果不需要,请尝试以下代码,跳过重写条件 download/.php ,确保您必须将 404 文件放入您的域文件夹中
希望它对您有帮助
Try this following code if not necessary skip the rewrite contidion download/.php ,make sure that you have to put a 404 file in your domain folder
Hope it helps you
好的,
因为我是 .htaccess-lame,所以我决定使用 jQuery 来解决我的问题。我使用 .attr() 来替换原始属性“href”。我已经设法更改子页面的链接:
上面的函数将我发送到 page#subpage,其中 PAGE 包含所有子页面的内容,单击 menu_on_HOME 链接会直接转到子页面锚点。此外,在实际的页面上,我有子页面的内部链接(内容可以通过cms作为页面进行编辑),但我不需要深入子页面,而是获得所需的锚点,所以我使用了 ScrollTo :
我不知道如何解决方案是“对”或“错”,但它对我来说完美无缺:)
Ok,
Since I'm a .htaccess-lame I decided to use jQuery to solve my problem. I used .attr() to replace the original attribute 'href'. I've managed to change the links to subpages with:
The function above sends me to page#subpage where PAGE contains the content of all subpages and clicking on the menu_on_HOME link goes straight to subpage anchor. Moreover, on the actual PAGE i have internal links to subpages (the content can be editable via cms as a page) but I didn't need to go deeper into subpage but rather get the desired anchor, so I used ScrollTo :
I don't know how 'right' or 'wrong' the solution is, however it works for me flawlessly :)