从 htaccess 重写到 codeigniter 控制器

发布于 2024-09-17 12:54:32 字数 485 浏览 9 评论 0原文

我的 codeigniter 应用程序目录结构类似于

--application
--htdocs
   --index.php
   --.htaccess
   --文件夹
      --file1.xml

现在我有一个网址 http://mysite.com/folder。这显示了文件夹目录中的文件列表。我想要的是将这个 url 重写为我网站上的控制器,即“html.php”。

注意:我不想重定向。我希望 url 相同,但不显示文件夹内容,而是希望将控件传递给控制器​​。我应该编写什么 .htaccess 规则?

My codeigniter application directory structure is like

--application
--htdocs
  
--index.php
  
--.htaccess
  
--folder
      
--file1.xml

Now I have a url http://mysite.com/folder. This is showing the files list in the folder directory. What I want here is to rewrite this url to a controller on my site say 'html.php'.

Note: I do not want to redirect. I want the url to be same but instead of showing folder contents, I want to pass the control to a controller. What .htaccess rule should I write?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖迟 2024-09-24 12:54:37

你看过url路由吗?

$route['folder'] = "html"; //html 是您的控制器

www.yoursite.com/folder

将“重定向”到 yoursite.com/html 但不会更改 URL。

无需搞乱 htaccess

编辑:

RewriteEngine On
RewriteBase /

#ignored folders/files
RewriteCond $1 !^(index\.php|robots\.txt|img/|css/|js/)

RewriteRule ^(.*)$ index.php?/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

从 - http://codeigniter.com/forums/viewthread/ 获得153228/

也许这就是你所追求的?

have you looked at url routing?

ie

$route['folder'] = "html"; //html is your controller

www.yoursite.com/folder

will "redirect" to yoursite.com/html but won't change the URL.

no need to mess with htaccess

edit:

RewriteEngine On
RewriteBase /

#ignored folders/files
RewriteCond $1 !^(index\.php|robots\.txt|img/|css/|js/)

RewriteRule ^(.*)$ index.php?/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

obtained from - http://codeigniter.com/forums/viewthread/153228/

perhaps this is what you are after?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文