CodeIgniter多应用程序.htaccess问题

发布于 2024-09-15 10:49:46 字数 2049 浏览 1 评论 0原文

我对 CodeIgniter .htaccess 文件有疑问,希望有人可以帮助我! 我不知道正则表达式或如何使用 .htaccess,我对这些东西很陌生!

我的问题是:

我有这样的文件结构(多应用程序):

- application
    - admin
    - site
- system
- index.php
- admin.php

并且这个 .htaccess (在本地主机上运行良好!)

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我想要做的是:

使用 http://www.mydomain.com/ 我的管理员(后端)为 http://www.mydomain.com/admin/

我不不知道为什么这在我的本地服务器上运行良好。

我希望有人能帮助我。

UPDATE

我使用以下方法让它工作:

RewriteEngine on

# If the user types "index.php" or "admin.php".
RewriteCond $1 !^(index\.php|admin\.php|images|robots\.txt)

# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin\.php [L,QSA]

# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ admin\.php/$1 [L,QSA]

# If the user types any site section, like "site/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php/$1 [L,QSA]

这样我就可以访问 http://www.mydomain.com/admin 或 http://www.mydomain.com/admin/any-section (指向根目录上的“admin.php”)

我可以访问 http://www.mydomain.com /http://www.mydomain.com/any-section (指向根目录上的“index.php”)

感谢您的帮助!

I have a problem with CodeIgniter .htaccess file and hope that somebody can help me!
I don't know regular expressions or how to use the .htaccess, I'm very new with this things!

My Problem is:

I have this structure of files (multi application):

- application
    - admin
    - site
- system
- index.php
- admin.php

And this .htaccess (that works fine on localhost!)

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

What I want to do is:

Access my web site (frontend) with http://www.mydomain.com/
And my admin (backend) as http://www.mydomain.com/admin/

I don't know why this works fine on my local server.

I hope someone can help me.

UPDATE

I got it to work using this:

RewriteEngine on

# If the user types "index.php" or "admin.php".
RewriteCond $1 !^(index\.php|admin\.php|images|robots\.txt)

# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin\.php [L,QSA]

# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ admin\.php/$1 [L,QSA]

# If the user types any site section, like "site/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php/$1 [L,QSA]

This way I can access http://www.mydomain.com/admin or http://www.mydomain.com/admin/any-section (that points to "admin.php" on the root directory)

And I can access http://www.mydomain.com/ or http://www.mydomain.com/any-section (that points to "index.php" on the root directory)

Thanks for the help!

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

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

发布评论

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

评论(1

梦归所梦 2024-09-22 10:49:46

首先,这是多余的:

RewriteCond $1 !^(index\.php|images|robots\.txt)

因为您的其他条件已经处理现有文件和目录,所以我建议删除它。

如果您希望 /admin 重写为 admin.php,则您的重写规则是错误的,按照您当前的规则,它将导致 /index.php/admin。您没有提到这是否是问题,如果是,请执行以下操作:

RewriteRule ^/admin$ admin.php [L,QSA]
RewriteRule ^(.*) index.php/$1 [L,QSA]

您也可以使用 RewriteLog 调试重写: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog

如果这不能解决问题,请描述当前的行为和您的期望,否则很难帮忙。

First of all this is redundant:

RewriteCond $1 !^(index\.php|images|robots\.txt)

because your other conditions already take care of existing files and directories so I'd suggest to remove it.

Your rewrite rule is wrong if you want /admin to rewrite to admin.php, with your current rule it will result in /index.php/admin. You didn't mention if that's the problem, if it is do this:

RewriteRule ^/admin$ admin.php [L,QSA]
RewriteRule ^(.*) index.php/$1 [L,QSA]

Also you can debug the rewriting using RewriteLog: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog

If that doesn't fix it please describe the current behaviour and what you expect, otherwise it's difficult to help.

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