所以我在我的服务器根目录中包含了一个 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/