dounue1965 2016-03-04 15:23
浏览 39
已采纳

htaccess更改重写规则以覆盖常见特定文件夹的WP多站点

I have several hosted clients and several subdomain clients, and I'd like to write .htaccess or php.ini rules to allow each of these sites, including my root site to have access to a common folder (/home/usr/public_html/public_scripts/) public that the clients (/home/usr/public_html/subdomains/client/) or (/home/usr/public_html/hosts/clients/) cannot see in ftp, but the root site can:

/home/usr
    |--/public_html
        |--/public_scripts/
        |
        |--/hosts
        |    |--/client
        |        |--/subdomains
        |
        |--/subdomains
            |--client

So that I can use this folder from:

www.mydomain.com/public_scripts/
subdomain.mydomain.com/public_scripts/
www.theirdomain.com/public_scripts/
subdomain.theirdomain.com/public_scripts/

I've tried:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^common/(.*)$ /home/usr/public_html/public_scripts/$1 [QSA]
</IfModule>

But this did not work. It simply redirects to /index.php

Shared hosting, so I do not have access to the httpd-conf file. I do have access to php.ini

it is matching correctly when I turn the WP rules off. I have both subdomain and domain mapping in my site, but I'm not sure if I need wp both sections or if I can combine all three into one rewrite rule.

Edit: Here's the rewrite rules I'm using, now that I realized I'm on a wordpress HTACCESS:

<IfModule mod_rewrite.c>
# BEGIN Wordpress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END Wordpress
</IfModule>
<IfModule mod_rewrite.c>
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^common/(.*)$ /home/usr/public_html/public_scripts/$1 [QSA]
</IfModule>

AddHandler application/x-apple-aspen-config .mobileconfig

But this did not work. It simply redirects to /index.php

Shared hosting, so I do not have access to the httpd-conf file. I do have access to php.ini

It is matching correctly when I turn the WP rules off. I have both subdomain and domain mapping in my site, but I'm not sure if I need wp both sections or if I can combine all three into one rewrite rule.

Here's the "working" htaccess. Some day I'll have to organize these when I have more time:

<IfModule mod_rewrite.c>
# BEGIN Wordpress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END Wordpress
</IfModule>
<IfModule mod_rewrite.c>
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# END WordPress

RewriteRule ^common/(.*)$ /home/usr/public_html/public_scripts/$1 [QSA]

# BEGIN WORDPRESS
RewriteRule . /index.php [L]
# END WORDPRESS
</IfModule>
AddHandler application/x-apple-aspen-config .mobileconfig
  • 写回答

1条回答 默认 最新

  • dongzhong7299 2016-03-05 10:35
    关注

    Seems like this rule is a catch all: RewriteRule . /index.php [L]. It will matching anything. Move your rule up.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 请教怎么绕过这个卡密系统 大家交流一下
  • ¥15 设计数字电路得到要求结果
  • ¥15 hfss 组天线阵列报错:The A and B vectors must be parallel to the XY plane,如何解决?
  • ¥30 ansible连接设备报错
  • ¥60 pmsampsize包取值问题
  • ¥15 波形合成电路的设计学习
  • ¥15 unity脚本挂不上
  • ¥15 数学建模数学建模需要
  • ¥20 Java Sound Api 调用Mixer.getLine偶现Line unsupported错误。
  • ¥15 使用cuda加速opencv运算但是报错AttributeError: module 'cv2.cuda' has no attribute 'getCudaEnabledDeviceCount'