【发布时间】:2018-04-15 10:35:39
【问题描述】:
我的网站有一个库/目录路径,例如:
{root}/pages/{files}.php
我的 index.php 路径如下:{root}/index.php
我希望,当人们访问(例如)“login.php”(存在于 /pages 目录中。该 url 不包含“/pages”时。
所以:
www.website.com/pages/dashboard.php
重定向到
www.website.com/dashboard.php
当人们访问 www.website.com/dashboard.php 时,他们可能会访问此页面。
抱歉解释不好,找不到好词。
编辑:这是我现在的 .htacces
RewriteEngine on
# Rewrite automatic to /index.
RewriteCond %{REQUEST_URI} ^/$
# Second check for if above doesn't do the job [www/https].
RewriteCond %{REQUEST_URI} !^/index [NC]
RewriteRule ^$ /index [R=301,L]
# Delete all the .php and .html extensions from files [url-related].
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Prevent people for looking inside the .htacces file.
<Files .htaccess>
order allow,deny
deny from all
</Files>
我确实尝试过这个: RewriteRule ^/?pages/(.*)$ /$1 [R=301,L]
(确实重定向了我,但仍然收到 404 错误。
【问题讨论】:
-
好吧,仅在 SO 上就有数百万个简单重定向规则的示例。所以问题是:您需要什么作为附加信息?为什么所有这些答案都不能回答您的问题?
-
我对 .htacces 的了解几乎为零。所以我可以尝试所有这些答案,我显然做到了。但在所有情况下,我最终得到的是: 1. 我无法直接浏览我的文件(所以当我尝试通过 /pages/file.php 时它确实重定向了,但是当访问链接只是 domain/file.php 2 时它没有工作. 或者它工作但重定向到我已经关闭的.php(带扩展名)。对我来说.htacces就像中文。
-
因此,请添加您所做的尝试以及对问题的准确描述,以便我们提供帮助。
-
确实为该主题添加了更多信息。
标签: php .htaccess redirect directory root