简体   繁体   中英

CodeIgniter .htaccess RewriteRule result in 404 Page Not Found

I used the following .htacces to route from an old page to a new one:

RewriteEngine on
RewriteCond %{REQUEST_URI} /Uploader2.7.0/secureFileUploader.php
RewriteRule ^(.*)$ /uploader/upload [L,QSA]  

Even though the rewrite rule is correct, I got a '404 page not found' error. This .htacces is at the root of my site.

Based on this answer , I changed:

$config['uri_protocol'] = 'AUTO';

to

$config['uri_protocol'] = 'REQUEST_URI';

And that made the reroute rule work fine, but the CLI stopped working. Then I saw this question which says it will work if I will change the 'uri_protocol' back to

$config['uri_protocol'] = 'AUTO';

Is there a way to make both work?

Note: the rewrite rule works, the issue is with the CodeIgniter internal routing. I can make it work either with the RewriteRule rule or with CLI, not both.

EDIT:

I want the url /Uploader2.7.0/secureFileUploader.php to become /uploader/upload internally, which i managed to do using the rule above.

/uploader in the path of Codeigniter index.php , and upload is the name of the controller I wish to route to.

Under /uploader I have the .htaccess file to hide the index.php of CodeIgniter, which works perfectly:

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

put your .htacces file at same level of application, user_guide folder. So u have total 6 file in your codeigniter folder including index.php and license text document as well as .htaccess file.

该图像对您有用

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