.htaccess RewriteRule 在子目录中不起作用

编程入门 行业动态 更新时间:2024-10-08 18:37:01
本文介绍了.htaccess RewriteRule 在子目录中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为我的网站的新版本编程,我正在尝试让 .htaccess 正确重写.我的新网站存储在这里:

I'm programming the new version of my website and I'm trying to get .htaccess to rewrite properly. My new site is stored here:

www.example/storage/new/

我需要重写这些 URL:

I need to rewrite these URLs:

www.example/storage/new/welcome/ -> index.php?action=welcome www.example/storage/new/page/name/ -> index.php?action=page&url=name www.example/storage/new/post/name/ -> index.php?action=post&url=name

这是我的 .htaccess 文件:

This is my .htaccess file:

RewriteEngine On RewriteRule ^/welcome/$ index.php?action=welcome [L] RewriteRule ^/page/([a-zA-Z0-9]+)/$ index.php?action=page&url=$1 [L] RewriteRule ^/post/([a-zA-Z0-9]+)/$ index.php?action=post&url=$1 [L]

然而,它不起作用;所有结果都是 404 Not Found.我什么都试过了,甚至用 www.example/storage/new/ 代替 ^.我在服务器根目录 (www.example) 中有另一个 .htaccess,如下所示:

It does not work, however; all results in a 404 Not Found. I've tried everything, even typing out www.example/storage/new/ in lieu of ^. I have another .htaccess in the server root (www.example) that looks like this:

RewriteEngine On RewriteCond %{HTTP_HOST} ^www.example$ [NC] RewriteRule ^(.*)$ example/$1 [R=301,L]

我无法想象这会如何影响 www.example/storage/new/ 但你永远不知道.有人能帮我解决这个问题吗?

I can't imagine how that would affect www.example/storage/new/ but you never know. Can anyone help me with this?

推荐答案

我不得不通过电子邮件向服务器管理员寻求帮助,结果发现 .htaccess 将自己的路径视为 root;我只是删除了每个规则中 ^ 之前的第一个 / .我的最终 .htaccess 文件如下所示:

I had to e-mail my server's administrator for help and it turns out that .htaccess treats its own path as root; I simply removed the first / before the ^ in each rule. My final .htaccess file looks like this:

RewriteEngine On RewriteRule ^welcome/$ index.php?action=welcome [L,QSA] RewriteRule ^page/(.*)/$ index.php?action=page&url=$1 [L,QSA] RewriteRule ^post/(.*)/$ index.php?action=post&url=$1 [L,QSA]

更多推荐

.htaccess RewriteRule 在子目录中不起作用

本文发布于:2023-11-02 06:13:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子目录   中不   htaccess   RewriteRule

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!