从 URL 中删除 2 个文件夹并重定向到页面

Removing 2 folders from URL and redirecting to page

我正在创建一个新的网络应用程序,这是我的项目文件夹的样子:

如您所见,我已在根文件夹中重命名了 htaccess,因为我没有使用它,而是使用位于 public 文件夹内的那个。我正在尝试更改我的 URLs:

http://example.site/public/pages/about

至:

http://example.site/about

我能够从文件扩展名中删除 .php,但是我添加的用于从 URL 中删除文件夹的代码不起作用。

注意:在根文件夹 (App/index.php) 中,index.php 文件只有这个:

<?php

header('Location: public/pages');

所以我只是用它发送到正确的文件夹。

这是我目前拥有的:

Options +FollowSymLinks -MultiViews

RewriteEngine on

RewriteBase /App/public/

RewriteRule ^pages/(.+)$ / [L,R=302,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) .php [NC,L]

我从这个url看到这个question/answer:

Remove / Rewrite 2 directory names from URL

但它对我不起作用。期待任何能提供帮助的人,谢谢。

假设 ``htdocs/app/is yourDocumentRootforapp.blu` 域。

htdocs/app/public/.htaccess 中,您可以使用此代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# if URL has /pages/ then remove and redirect
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^pages/(.+)$ / [L,R=301,NC]

# landing page for app subdomain to show index.php
RewriteRule ^$ pages/index.php [L]

# check & rewrite if a matching .php file exists in pages/ subdirectory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/public/pages/.php -f
RewriteRule ^(.+?)/?$ pages/.php [L]

除此之外,您还需要在 htdocs/app/.htaccess:

中使用此代码
Options +FollowSymLinks -MultiViews
RewriteEngine on

# send all the traffic to /public/
RewriteRule .* public/[=11=] [L]