简体   繁体   English

如何使用.htaccess重定向所有请求

[英]How to redirect all requests with .htaccess

So, here's what my folder structure is like: 因此,这是我的文件夹结构:

/
  /public/
     /index.php
     /app/
.htaccess

I want that when I type www.example.com the request go to the public\\index.php file but don't display the public . 我希望当我输入www.example.com ,请求转到public\\index.php文件,但不显示public And if I go to www.example.com\\app it goes to \\public\\app but only shows www.example.com\\app . 如果我转到www.example.com\\app它将转到\\public\\app但仅显示www.example.com\\app

Is that possible with .htaccess? .htaccess有可能吗?

In your site root .htaccess you can use this: 在您的网站根目录.htaccess中,您可以使用以下命令:

DirectoryIndex index.php
RewriteEngine On

# add trailing slash in front of directories
RewriteCond %{DOCUMENT_ROOT}/public/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=301,NE]

# internally forward to /public/...
RewriteRule !^public/ public%{REQUEST_URI} [L,NC]

This should work: 这应该工作:

RewriteRule ^$  /public/index.php [L] 

RewriteCond %{REQUEST_URI} !^/public [NC]
RewriteRule ^(.*)$  public/$1 [L]

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

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