![](/img/trans.png)
[英]Redirecting to the same page with PHP headers is not removing the GET request from the URL
[英]Removing 2 folders from URL and redirecting to page
我正在创建一个新的 web 应用程序,这就是我的项目文件夹的样子:
如您所见,我已将根文件夹中的 htaccess 重命名,因为我没有使用该 htaccess,而是使用位于公用文件夹内的那个。 我正在尝试从此更改我的网址:
http://example.site/public/pages/about
至:
我能够从文件扩展名中删除 .php 但我添加的用于从 URL 中删除文件夹的代码不起作用。
注意:在根文件夹 (App/index.php) 中的 index.php 文件只包含以下内容:
<?php
header('Location: public/pages');
所以我只是用它来发送到正确的文件夹。
这是我到目前为止所拥有的:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /App/public/
RewriteRule ^pages/(.+)$ /$1 [L,R=302,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) $1.php [NC,L]
我从这个 url 中看到了这个问题/答案:
但这对我不起作用。 期待能帮忙的人,谢谢。
假设 ``htdocs/app/ is your
for
app.blu` 域的 DocumentRoot。
在htdocs/app/public/.htaccess
中,您可以使用以下代码:
Options +FollowSymLinks -MultiViews
RewriteEngine on
# if URL has /pages/ then remove and redirect
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^pages/(.+)$ /$1 [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/$1.php -f
RewriteRule ^(.+?)/?$ pages/$1.php [L]
除此之外,您还需要在htdocs/app/.htaccess
中使用此代码:
Options +FollowSymLinks -MultiViews
RewriteEngine on
# send all the traffic to /public/
RewriteRule .* public/$0 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.