简体   繁体   English

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

[英].htaccess rewrite parent folder to sub folder

how can i redirect from server.ip/~bogo/api/* to server.ip/~bogo/api/public/*? 我如何从server.ip /〜bogo / api / *重定向到server.ip /〜bogo / api / public / *? any help please 任何帮助请

Here's htacces in api directory 这是api目录中的htacces

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

my htacces in public directory 我在公共目录中的htacces

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

but i got 404 error?? 但我收到404错误?

Ok i solved it here's my solution 好吧,我解决了这是我的解决方案

api directory htaccess api目录htaccess

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

public directory htaccess 公共目录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 will go through .htaccess until no rules match anymore. Apache将通过.htaccess直到没有规则匹配。 The problem you are most likely facing, is that the new url is being matched by the regex of the same rule. 您最有可能面临的问题是,新URL被同一规则的正则表达式匹配。 You have created an infinite loop. 您已经创建了一个无限循环。 You can fix this by making sure the rule doesn't match if the url already has 'public' in it: 您可以通过以下方法解决此问题:如果网址中已经包含“ 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