[英]How do I remove a word from a url in Wordpress using .htaccess?
In the site I'm building there is a post-type
called "Focus". 在我正在构建的网站中,有一个称为“焦点”的
post-type
。 Since they need to url to be like www.mysite.com/focus/page-post-name
I have the post type slug as "focus". 由于他们需要输入网址才能像
www.mysite.com/focus/page-post-name
一样,因此我将帖子类型为“ focus”。
Of course the archive page is www.mysite.com/focus
this is causing an issue since I need a specific page to be an archive page. 当然,存档页面是
www.mysite.com/focus
这会引起问题,因为我需要将特定页面作为存档页面。 Metaboxes are used to build and add settings to pages. 元框用于构建页面并向页面添加设置。 I can't just create a page called "Focus" since that is reserved by the
post-type
. 我不能仅创建一个名为“ Focus”的页面,因为该页面是由
post-type
保留的。
My idea is to create a page called "Our Focus" resulting a URL of www.mysite.com/our-focus
. 我的想法是创建一个名为“我们的焦点”的页面,其网址为
www.mysite.com/our-focus
。
I'd like to just remove the "our-" from that url to make it appear that the archive is being used. 我只想从该网址中删除“我们的”,以使其看起来好像正在使用存档。
I've tried setting has_archive
to false but that just reverts to using the archive.php page. 我尝试将
has_archive
设置为false,但这只是恢复为使用archive.php页面。
I'm mobile and working without access to a test server, so forgive any errors. 我正在移动并且无法访问测试服务器,因此请原谅任何错误。
It sounds like you need mod_rewrite, it should be packaged with apache, but may be off. 听起来您需要mod_rewrite,应该将其与apache打包在一起,但可能已关闭。 Typically you'll have to check the mods_enabled directory in your apache conf directory, or search your conf file for rewrite.
通常,您必须检查apache conf目录中的mods_enabled目录,或搜索conf文件以进行重写。
You'll need two lines in your htaccess at least. 您的htaccess中至少需要两行。
RewriteEngine on
RewriteRule ^/focus/?$ /our-focus/
First line is required to enable rewrite. 需要第一行来启用重写。 The second line is the rule declaration, a regex to match, and a destination.
第二行是规则声明,要匹配的正则表达式和目标。 The regex should only match focus, and direct you accordingly.
正则表达式只能匹配焦点,并据此指导您。 Wordpress may take issue, but I think this will work.
WordPress可能会出现问题,但我认为这会起作用。
Docs for reference 文件供参考
http://httpd.apache.org/docs/current/mod/mod_rewrite.html http://httpd.apache.org/docs/current/mod/mod_rewrite.html
You may need RewriteBase
depending on setup. 根据设置,您可能需要
RewriteBase
。 RewriteBase is typically used if there are virtualHosts or a different base url then the server expects. 如果有virtualHosts或服务器期望的其他基本URL,通常使用RewriteBase。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.