.htaccess将父文件夹重写到子文件夹

时间:2014-07-24 10:18:20

标签: php .htaccess

如何从server.ip / ~bogo / api / *重定向到server.ip / ~bogo / api / public / *? 任何帮助,请

这是api目录中的htacces

   <IfModule mod_rewrite.c>
    RewriteEngine on
     RewriteRule  ^$ public/    [L]
      RewriteRule  (.*) public/$1 [L]
    </IfModule>

我公共目录中的htacces

 <IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

但我得到了404错误?

2 个答案:

答案 0 :(得分:1)

好的,我在这里解决了我的解决方案

api目录htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /~bogo/api/
RewriteCond %{REQUEST_URI} !/public/
RewriteRule  (.*) public/$1
</IfModule>

公共目录htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /~bogo/api/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

答案 1 :(得分:0)

Apache将通过.htaccess,直到没有规则匹配为止。您最有可能面临的问题是新网址与同一规则的正则表达式相匹配。你创造了一个无限循环。您可以通过确保规则不匹配来解决此问题:如果网址中已包含“公开”:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteCond %{REQUEST_URI} !/public/
  RewriteRule (.*) public/$1 [L]
</IfModule>
相关问题