HTaccess 不重新路由 [CodeIgniter]

发布于 2024-12-09 05:29:47 字数 381 浏览 0 评论 0原文

我有一个应用程序,在使用完整网址时效果很好:sitename.com/index.php/foo/,但是当我使用 HTaccess 删除 index.php 时,它似乎没有按预期工作。无论我访问哪个页面,我都只能看到主页。 htaccess 文件正在执行某些操作,因为如果没有该行,我会收到 404 错误。

    RewriteEngine on
    RewriteCond $1 !^(index\.php|assets|file-manager-files|robots\.txt|favicon\.ico)
    RewriteRule ^(.*)$ /index.php/$1 [L]

想法?

在我的测试站点上一切正常。这是需要调整的服务器设置吗?

I have an application that works great when using the full url: sitename.com/index.php/foo/ but when I use HTaccess to remove the index.php it doesn't seem to work as expected. No matter which page I access I only see the home page. The htaccess file is doing something because without that line I get a 404 error.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|assets|file-manager-files|robots\.txt|favicon\.ico)
    RewriteRule ^(.*)$ /index.php/$1 [L]

Thoughts?

On my test site everything works just fine. Is this a server setting that needs to be tweaked?

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

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

发布评论

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

评论(2

↙厌世 2024-12-16 05:29:47

使用 Codeigniter,您想要这样的东西:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>  

如果这不起作用,请检查以确保 $config['index_page'] = ''; 和您的 .htaccess 指令设置正确:

<Directory "/some/absolute/path/htdocs">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>  

我已经做了数百次Codeigniter 的安装在许多操作系统配置上,并且始终能够使其正常工作,但我偶尔会遇到一些问题,我必须发挥创意才能让 index.php 消失。

With Codeigniter you want something like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>  

If that is not working, check to make sure $config['index_page'] = ''; and your .htaccess directives are set right:

<Directory "/some/absolute/path/htdocs">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>  

I've done hundreds of Codeigniter installs on many OS configs and have always been able to get this to work, but I have had some issues occasionally where I had to get creative to get the index.php to disappear.

笛声青案梦长安 2024-12-16 05:29:47

RewriteCond 是错误的。在第一个参数中,您必须使用要检查的内容。例如请求的 URI、脚本文件名等。在上面的示例中,您似乎尝试将 $1(美元和一)与重写条件的右侧部分进行比较:?

The RewriteCond is wrong. In first argument you have to use what to check. In example the requested URI, the script file name and so on. On the above example it looks like you try to compare $1 (dolar and one) to the right part of the Rewrite Condition :?

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