【发布时间】:2016-04-16 20:32:52
【问题描述】:
我的网站结构如下:
root
|
|----- .htaccess
|----- public
|
|----- index.php (has all Autoload classes)
|----- application
| ---- controllers
| ---- models etc
现在您可能已经注意到我的根目录中没有index.php/.html,我故意这样做是因为我希望服务器通过.htaccess 重定向。
如果您作为用户访问网站说:
http://localhost/testRedirect then it shall point to `public` folder
在目录中而不在 URL 中显示 public。
我尝试了 SO 的打击解决方案,声称可以按我的意愿工作:
解决方案 1 [这只是显示目录结构 :( ]
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{HTTP_HOST} ^localhost\$
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1
#RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{HTTP_HOST} ^localhost\$
RewriteRule ^(/)?$ public [L]
解决方案 2 [给出 404 :( ]
RewriteEngine on
RedirectMatch ^/$ /public/
解决方案 3 [重定向但在 URL 中显示 public。
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{HTTP_HOST} ^localhost\$
#RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule (.*) http://localhost/testRedirect/$1 [R=301,L]
RewriteRule ^$ public [L]
请推荐一些不错且有效的 htaccess
【问题讨论】:
标签: php apache .htaccess redirect mod-rewrite