繁体   English   中英

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

[英].htaccess rewrite parent folder to sub folder

我如何从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错误?

好吧,我解决了这是我的解决方案

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>

Apache将通过.htaccess直到没有规则匹配。 您最有可能面临的问题是,新URL被同一规则的正则表达式匹配。 您已经创建了一个无限循环。 您可以通过以下方法解决此问题:如果网址中已经包含“ public”,请确保规则不匹配:

<IfModule mod_rewrite.c>
  RewriteEngine on

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM