简体   繁体   中英

Apache mod_rewrite Clean URLs

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!

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 ie

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>

尝试添加rewritebase RewriteBase /Path/to/directory/DirectoryBelowApps/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM