apache - 开始实现 .htaccess,但从简化的 URL 导航时,进入目录时无法返回

标签 apache .htaccess mod-rewrite url-rewriting friendly-url

所以我在我的服务器根目录中包含了一个 htaccess 文件,并更改了所有我可以找到的设置绝对值的 ./。 但是,当我通过 URL 搜索其中一个目录时,按主页按钮不会带我回家。相反,它将索引附加到末尾:

/website/book/index.php?p=home 代替 /website/index.php?p=home

我哪里搞错了?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+[^/])/$ https://%{HTTP_HOST}/paperbound/$1 [R=301,L]
RewriteRule ^([^/\.]+)?$ index.php?p=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?p=$1&id=$2 [NC,L]
</IfModule>

是否使用了htaccess。 https://sitehost/website/book/2 是输入的 URL 和检索的页面,其存在形式为 https://sitehost/website/index.php?p=book&id=2,单击导航链接返回到 https://sitehost/website/index.php?p=home,而是放置 https://sitehost/website/book/index.php?p =home 进入 URL 栏并返回错误,因为该文件不存在。

最佳答案

根据您显示的示例/尝试,请尝试遵循 htaccess 规则文件。确保您的 index.php 文件存在于网站文件夹中,并且 htaccess 与网站文件夹一起存在(而不是在其中)。

在测试您的网址之前,请确保清除浏览器缓存。

##Enabling rewrite engine here.
RewriteEngine ON
##Checking conditions for non-existing pages here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##performing internal rewrite here to index.php file.
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$  $1/index.php?p=$2&id=$3 [QSA,L]

关于apache - 开始实现 .htaccess,但从简化的 URL 导航时,进入目录时无法返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70507928/

相关文章:

django - 带有 django 和 mod_wsgi 的基于 SSL 的虚拟主机

django - 在 View 中使用 redirect() 时 session ID 会发生变化

c++ - 在 FastCGI 和 Octave 中重新定义标准输出

.htaccess - htaccess 或 php 301 重定向 url

.htaccess - htaccess 重写会破坏相对路径

java - 如何使用 Java 获取 VHost 服务器名称?

PHP - URL 重写在 htaccess 中不起作用

php - 在 codeigniter 中删除 index.php(在本地工作正常但在生产环境中不工作)

apache - .htaccess 文件在带有 apache2 的 Ubuntu 14.04 上不起作用

.htaccess 仅在某些页面上设置 SSL 重定向时无法正常工作