Question
How can I remove /public/ from my URLs?
Problem
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
Setup
/app/ .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
This works fine. When I visit localhost:8888/app/
it loads up the index.php
file inside the public folder.
/app/public/ .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
Related:
URL-rewriting with index in a "public" folder
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…