.htaccess的公用文件夹重写规则

编程入门 行业动态 更新时间:2024-10-28 02:31:25
本文介绍了.htaccess的公用文件夹重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我工作在PHP有点定制MVC项目时遇到的htaccess的一些问题。本来,我的htaccess的是路由的所有流量在我的根目录的index.php,并通过其余的路径作为参数。这是工作完美地与此code:

I'm working on a little custom MVC project in PHP and am having some issues with the htaccess. Originally, my htaccess was routing all traffic to index.php in my root dir, and passing the remaining path as an argument. This was working perfectly with this code:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ index.php?path=$1 [NC,L,QSA]

我有现在的问题是,我需要index.php文件移动到/ public目录。为此,我在网上寻找答案,并发现了一个code片断的有点的工作,因为它似乎到那里只要是刚打/,但只要链接变为/寄存器/或其他任何东西,它只是404的。

The problem I'm having now is that I need to move the index.php file into a /public directory. I scoured the internet for answers, and found a code snippet that kinda works in that it seems to get there as long as it is just hitting /, but as soon as the url becomes /register/ or anything else it just 404's.

# Get rid of /public/ in the URL, and route all requests through # the Index.php file RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ /public/index.php?path=$1 [NC,L,QSA] RewriteCond %{REQUEST_URI} !/public/ [NC] RewriteRule ^(.*?)/?$ public/$1 [L]

我知道,最后一行使得当有重写到index.php呢?这似乎正确的,我(至少它传递参数就像我想要的!)路径没有任何意义,但没有这两行它不似乎工作,我一直在尝试和示数这几个小时。希望有人可以帮帮忙!干杯!

I know that last line makes no sense in when there is the rewrite to index.php with ?path that seems proper to me (at least it passes the argument like I want!) but without both these lines it doesn't seem to work, and I've been trial-and-erroring this for hours. Hopefully someone can help out! Cheers!

推荐答案

请在你的.htaccess仅此内容:

Keep only this content in your .htaccess:

DirectoryIndex index.php RewriteEngine On RewriteRule ^/?$ public/ [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ public/?path=$1 [L,QSA]

更多推荐

.htaccess的公用文件夹重写规则

本文发布于:2023-07-12 07:27:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1096857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   文件夹   规则   htaccess

发布评论

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

>www.elefans.com

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