简体   繁体   English

使用.htaccess从某些URL中删除Wordpress目录名称

[英]Removing Wordpress directory name from certain URLs using .htaccess

So I have one Wordpress install in a sub-directory. 因此,我在一个子目录中安装了一个Wordpress。 (www.mysite.com/wp/) (www.mysite.com/wp/)

What I need is for certain pages to remove the WP directory name from the URL. 我需要某些页面从URL中删除WP目录名称。

so 'www.mysite.com/wp/careers' needs to be -> 'www.mysite.com/careers' 因此“ www.mysite.com/wp/careers”必须为->“ www.mysite.com/careers”

I have an .htaccess in the root directory and in the wp directory. 我在根目录和wp目录中都有一个.htaccess文件。 I've gotten some of my rules to work when permalinks are disabled in WP, but when those are enabled (which they need to be) the WP .htaccess overrides any rules I have in the root. 当在WP中禁用永久链接时,我有一些规则可以使用,但是在启用(需要)永久链接时,WP .htaccess会覆盖我在根目录中拥有的所有规则。

Is there any way to have 2 htaccess co-exist in this manner? 有什么办法可以使2 htaccess以这种方式共存吗? Sorry I haven't messed with wordpress and apache very much. 抱歉,我还不太喜欢wordpress和apache。

Any input is greatly appreciated. 任何输入,不胜感激。

* *So I finally got this working, it was just a matter of like you said formatting redirect URL so wordpress likes it. * *因此,我终于可以正常工作了,就像您说的那样设置重定向URL的格式,以便wordpress喜欢它。

So in my root htaccess file : for this url mysite.com/careers 因此,在我的htaccess根文件中:对于此URL mysite.com/careers

RewriteRule ^careers/?$ wp/index.php?pagename=careers [L] RewriteRule ^ careers /?$ wp / index.php?pagename = careers [L]

And voila and it started working just fine. 瞧,它开始工作正常。

Yes, you can have rules in both htaccess files but it's going to be tricky as wordpress has specific ways that it will expect URLs to look. 是的,您都可以在两个htaccess文件中都有规则,但是由于wordpress具有期望URL查找的特定方式,因此这将非常棘手。

In the wordpress htaccess file, above any wordpress related rules, add: 在wordpress htaccess文件的任何与wordpress相关的规则上方,添加:

RewriteCond %{THE_REQUEST} \ /+wp/careers
RewriteRule ^ /careers [L,R]

then in the htaccess file in the document root add: 然后在文档根目录的htaccess文件中添加:

RewriteRule ^careers$ /wp/careers [L]

But again, depending on what wordpress expects the "careers" URL to look like, this may not solve your problem. 但是同样,根据wordpress期望“职业” URL看起来的样子,这可能无法解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM