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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵