Apache mod_rewrite干净的URL [英] Apache mod_rewrite Clean URLs

查看:67
本文介绍了Apache mod_rewrite干净的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP上使用CodeIgniter,它会产生以下URL:

I am using CodeIgniter on PHP and it produces the following URLs:

http://my.domain.com/app/index.php?/admin/main/

/index.php?是多余的,因此我可以使用以下重写规则将其成功删除:

the /index.php? is redundant so I remove it successfully with the following rewrite rule:

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

但是,我也想删除/app部分,但是当我这样做时,出现500错误.这与Code Igniter有关吗?或者我如何正确地重写此规则(如果可能)?我尝试了以下方法:

however, I would also like to remove the /app part, but when I do so, I get a 500 error. Is this related to Code Igniter - or how do I rewrite this rule correctly (if possible)? I tried with the following:

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ./app\/index.php/$1 [L]

谢谢!

推荐答案

对不起,但是如果htaccess位于项目的主目录中,那是为CI编写htaccess的一种非常古老的方法,只需使用下面的通用htaccess代码即可(这不需要排除的目录,例如旧目录,即

Sorry but that is a really old way of writing the htaccess for CI if the htaccess is in the main dir of the project just use the universal htaccess code below (this does not need excluded directories and such like the old one i.e.

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

所以它也更好,就像我说的通用)

so it is also better and like I said universal)

*这不会解决您的目录问题,但这是CI处理index.php删除的最佳方法,而无需在每次添加诸如docs文件夹之类的内容时都返回.

*It will not solve your issue with the directory but this is the best way for CI in handling the index.php removal without having to go back each time you add say a docs folder or something.

很棒的htaccess:

Awesome htaccess:

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

这篇关于Apache mod_rewrite干净的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆