htaccess的重写规则不工作的子目录

htaccess的重写规则不工作的子目录

本文介绍了htaccess的重写规则不工作的子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程我的网站的新版本,我试图让的.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.com/storage/new/

我需要重写这些URL:

I need to rewrite these URLs:

www.example.com/storage/new/welcome/   -> index.php?action=welcome
www.example.com/storage/new/page/name/ -> index.php?action=page&url=name
www.example.com/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未找​​到。我用尽了一切办法,甚至打字了 www.example.com/storage/new / 代替 ^ 。我已经在服务器的根目录另外的.htaccess( www.example.com ),看起来是这样的:

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

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

我无法想象如何会影响到 www.example.com/storage/new / ,但你永远不知道。谁能帮我这个?

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

推荐答案

我不得不电子邮件我的服务器的管理员的帮助和事实证明的.htaccess对待自己的路径根;我只是删除了第一个 / ^ 中的每个规则之前。我最后的.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的重写规则不工作的子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:12