我正在为我的网站的新版本编程,我正在尝试让 .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 在子目录中不起作用
发布评论