Apache mod_rewrite Clean URLs

£可爱£侵袭症+ 提交于 2019-12-25 03:53:16

问题


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

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

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]

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]

Thanks!


回答1:


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)

*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.

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>



回答2:


Try adding rewritebase RewriteBase /Path/to/directory/DirectoryBelowApps/



来源:https://stackoverflow.com/questions/5574127/apache-mod-rewrite-clean-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!