gpt4 book ai didi

regex - .htaccess:从 URL 中删除 public

转载 作者:行者123 更新时间:2023-12-04 02:42:03 26 4
gpt4 key购买 nike

问题

如何从我的网址中删除 /public/

问题

当我访问 /app/about 时,URL 更改为 /app/public/about 并且 app/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

最佳答案

您的 # 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]

关于regex - .htaccess:从 URL 中删除 public,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19708714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com