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.

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么