1

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. 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. All pages, videos, sales, etc are made from within wordpress pages.

The affiliate application is in a subdirectory /aff/ and affiliates' pages are found at 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.

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

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.

# 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. 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)

#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? How would I go about doing that?

Thanks in advance.

4

1 回答 1

1

RewriteRule错误地使用 s 代替RewriteConds。在 WordPress 规则之间添加它们肯定也会破坏您的博客。.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>

如果您希望 URL 保留,请mydomain.com/affiliate删除[R]并仅使用[QSA,L].


我已经更新了上面的规则,以展示如何从会员重定向中排除路径。以下

RewriteCond %{REQUEST_URI} !^/blog\b

从重定向中排除所有指向/blog或其子目录的URL。/blog/sub/dirs


如果存在根级.php页面(即使它们很少),则可以通过将规则更改为

RewriteRule ^([^/.]+)$ /aff/index.php?aff=$1 [R=301,QSA,L]

假设 a.和 a/永远不会出现在附属名称中。

于 2013-10-14T18:47:46.850 回答