[英]Modifying wordpress htaccess to forward certain urls to subdirectory
For whatever reason or another I haven't been able to ascertain, my company has decided to go with wordpress for one of their websites. 无论出于何种原因或我无法确定的其他原因,我的公司都决定将wordpress用于其网站之一。 They asked me to build an affiliate application on the same domain, which I did.
他们要求我在同一个域上构建一个联属网络营销应用程序。 Everything works great with the exception of this dilemma:
除以下两难之外,一切工作都很好:
wordpress is installed in the root directory. wordpress安装在根目录中。 All pages, videos, sales, etc are made from within wordpress pages.
所有页面,视频,销售等均来自Wordpress页面。
The affiliate application is in a subdirectory /aff/ and affiliates' pages are found at mydomain.com/aff/index.php?aff=affiliateusername 会员应用程序位于子目录/ aff /中,而会员的页面位于mydomain.com/aff/index.php?aff=affiliateusername中
Affiliates (and their leads) should be able to load their pages simply by typing in www.mydomain.com/affiliateusername but I am struggling to understand how to translate wordpress htaccess rules to do this. 会员(及其潜在客户)应该只需输入www.mydomain.com/affiliateusername即可加载其页面,但我仍在努力了解如何翻译wordpress htaccess规则来做到这一点。
Obviously the best order in which to have this work is for wordpress to first determine if there are any blogs/posts/pages that match the url term FIRST, and if none is found, then to redirect all else to www.mydomain.com/aff/index.php?aff=whatever 显然,进行此工作的最佳顺序是让wordpress首先确定是否有任何与网址词FIRST相匹配的博客/帖子/页面,如果找不到,则将所有其他内容重定向到www.mydomain.com/ AFF /的index.php?AFF =什么
Here's what I was finally able to come up with that works for the index page and for the affiliate pages, but does not correctly load any wordpress pages other than index. 这就是我最终想出的方法,该方法适用于索引页面和会员页面,但是没有正确加载除索引之外的任何wordpress页面。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(images|wp-admin|wp-content|wp-includes|go|compliance\.html)($|/) - [L]
#RewriteRule ^([^/].*)$ /aff/index.php?aff=$1 [R,L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You can tell I've attempted to exclude certain directories from the rewrite but have not been successful. 您可以告诉我,我试图从重写中排除某些目录,但是没有成功。 I've read other advice via Googling, to put the redirect rules ahead of the wordpress block, but there are few issues.
我已经通过Googling阅读了其他建议,将重定向规则放在wordpress块的前面,但是问题很少。 When I put this line ahead of the # BEGIN WordPress line, I get an endless redirect loop which keeps going to /aff/index.php?aff=aff/index.php?... etc (this is the same line I use for the same affiliate application on a different, wordpress-free, domain)
当我将此行放在#BEGIN WordPress行的前面时,我得到了一个无限循环的重定向循环,该循环不断转到/aff/index.php?aff=aff/index.php?...等(这是我使用的同一行对于不同的,无wordpress的域中的同一会员应用程序)
#RewriteRule ^([^/].*)$ http://www.mydomain.com/aff/index.php?aff=$1 [L]
I feel like I'm missing something terribly obvious. 我感觉好像缺少了非常明显的东西。 Should I just be setting up wordpress to redirect all 404's to /aff/index.php?aff=originalrequest?
我应该只是设置wordpress将所有404重定向到/aff/index.php?aff=originalrequest吗? How would I go about doing that?
我将如何去做?
Thanks in advance. 提前致谢。
You are using RewriteRule
s incorrectly in place of RewriteCond
s. 您使用了
RewriteRule
而不是RewriteCond
。 Adding them in between the WordPress rules is surely breaking your blog as well. 在WordPress规则之间添加它们肯定也会破坏您的博客。 Change your
.htaccess
code to: 将您的
.htaccess
代码更改为:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ /aff/index.php?aff=$1 [R=301,QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
If you want the URL to stay mydomain.com/affiliate
remove the [R]
and use only [QSA,L]
. 如果您希望URL保留为
mydomain.com/affiliate
删除[R]
并仅使用[QSA,L]
。
RewriteCond %{REQUEST_URI} !^/blog\\b
excludes all URLs pointing to /blog
or its sub-directories /blog/sub/dirs
from redirection. 从重定向中排除所有指向
/blog
或其子目录/blog/sub/dirs
URL。
.php
pages present (even if they are few) the exclusion can more easily be handled by changing the rule to
.php
页面(即使页面很少),则可以通过将规则更改为来更轻松地处理排除
RewriteRule ^([^/.]+)$ /aff/index.php?aff=$1 [R=301,QSA,L]
assuming that a .
假设
.
and a /
can never be present in an affiliate name. 并且
/
永远不能以会员名称出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.