的.htaccess:从URL删除公众 [英] .htaccess: remove public from URL
问题描述
问题
如何删除的 /公/ 的从我的网址?
How can I remove /public/ from my URLs?
问题
当我去参观 /应用/关于
的网址更改为 / APP /公/约
和应用/用户/ 2
修改 /app/user.php/?username=2
When I go to visit /app/about
the URL changes to /app/public/about
and app/user/2
changes to /app/user.php/?username=2
设置
在的.htaccess
之外的的公开的文件夹中包含:
The .htaccess
outside of the public folder contains:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /app/
# remove /public/ from URL
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)/?$ public/$1
这工作得很好。当我访问本地主机:8888 / APP /
,它加载了的index.php
文件中的公共的文件夹。
This works fine. When I visit localhost:8888/app/
it loads up the index.php
file inside the public folder.
在的.htaccess
里面的公开的文件夹中包含:
The .htaccess
inside of the public folder contains:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Add trailing slash
RewriteCond %{REQUEST_URI} ^(.+[^/])$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/ [L,R=301]
# API Pages
# ------------------------------------------------------------
RewriteRule ^user/([a-z0-9]+)/?$ user.php?username=$1 [L,NC]
# Generic Pages
# ------------------------------------------------------------
RewriteRule ^about/?$ about.php [L,NC]
# Error Pages
# ------------------------------------------------------------
ErrorDocument 404 /404.php
相关: <一href="http://stackoverflow.com/questions/13165966/url-rewriting-with-index-in-a-public-folder">URL-rewriting与指数在&QUOT;公开];文件夹
推荐答案
您#添加斜线
规则似乎是问题。你可以尝试注释掉它进行测试。
Your # Add trailing slash
rule appears to be problem. Can you try commenting it out for testing.
/app/.htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /app/
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+(.+?[^/])[?\s] [NC]
RewriteRule ^ /%1/ [L,R=301]
# remove /public/ from URL
RewriteCond %{REQUEST_URI} !/public/ [NC]
RewriteRule ^(.*?)/?$ public/$1 [L]
这篇关于的.htaccess:从URL删除公众的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!