.htaccess:从URL中删除public

rbpvctlc  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(122)

问题

如何从URL中删除 /public/

问题

当我访问/app/about时,URL更改为/app/public/aboutapp/user/2更改为/app/user.php/?username=2

设置

/app/ .htaccess

  • public* 文件夹外的.htaccess包含:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /app/

# remove /public/ from URL
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)/?$ public/$1

字符串
这个很好用。当我访问localhost:8888/app/时,它会加载 public 文件夹中的index.php文件。

/app/public/ .htaccess

  • public* 文件夹中的.htaccess包含:
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

相关URL-rewriting with index in a "public" folder

yb3bgrhw

yb3bgrhw1#

您的# Add trailing slash规则似乎有问题。你能试着把它注解出来进行测试吗?

/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]

字符串

相关问题