简体   繁体   English

使用htaccess重写网址以强制加载index.php

[英]url rewrite using htaccess to force load index.php

I'm trying to make a user-friendly author page url for my wp site. 我正在尝试为我的wp网站创建一个用户友好的作者页面网址。 Currently what I have done is I have created a folder by name author under my root theme folder and I have put my author page mark-up file( index.php ) inside this folder. 目前,我要做的是在根主题文件夹下创建一个按名称author命名的文件夹,并将作者页面标记文件( index.php )放入该文件夹中。

I also have a plugin ' Easy url rewrite ' which I'm using to make www.sitename.com/author request to load <theme dir>/author/index.php file. 我也有一个插件' Easy url rewrite ',它用于发出www.sitename.com/author请求以加载<theme dir>/author/index.php文件。 And it is working fine. 而且工作正常。

Now I want any www.sitename.com/author/<anyname> also to load my index.php file. 现在,我还希望任何www.sitename.com/author/<anyname>都加载我的index.php文件。

Can I achieve this using .htaccess rules? 我可以使用.htaccess规则来实现吗? Does .htaccess rule conflict with my url-rewrite plugin?(which one will be executed first?) Can I achieve this whole thing using only .htaccess rules(ie., without the use of plugin rewrite) If so, What rules do I need to write in .htaccess file? .htaccess规则是否与我的url-rewrite插件冲突?(哪个将首先执行?)是否可以仅使用.htaccess规则(即,不使用插件重写)来完成整个操作?需要写在.htaccess文件中?

Thanks! 谢谢! Greatly appreciate your help. 非常感谢您的帮助。

Does .htaccess rule conflict with my url-rewrite plugin .htaccess规则是否与我的url重写插件冲突

yes, probably. 应该是。

which one will be executed first? 哪个将首先执行?

The htaccess rules get executed first, but that's part of how wordpress works. htaccess规则首先被执行,但这是wordpress工作方式的一部分。 There are rules that essentially send everything to wordpress' controller and then wordpress handles it from there. 有些规则实际上会将所有内容发送到wordpress的控制器,然后wordpress从那里处理它。

Can I achieve this whole thing using only .htaccess rules 我可以仅使用.htaccess规则来完成全部工作吗

It depends. 这取决于。 Is your page generated by wordpress or is it just a page by itself separate from wordpress? 您的页面是由wordpress生成的,还是仅与wordpress分开的页面? If it's the former, you're going to need to work on some more easy url rewrite rules, if the author page is separate from wordpress then you can do this entirely with htaccess. 如果是前者,那么您将需要处理一些更简单的url重写规则,如果作者页面与wordpress分开,则可以完全使用htaccess做到这一点。

If that's the case, I'd guess the rules would look something like: 如果是这样,我猜规则看起来像这样:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^author/(.*)$ /themedir/author/index.php [L]

Those rules need to be before any wordpress rules that you have in the htaccess file in your document root. 这些规则必须在文档根目录中htaccess文件中具有的所有wordpress规则之前。

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

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