CodeIgniter Forums
.htaccess RewriteRule doesn't work as expected - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: .htaccess RewriteRule doesn't work as expected (/showthread.php?tid=74495)



.htaccess RewriteRule doesn't work as expected - ergec - 10-01-2019

I tested this on a fresh Codeigniter 3.1.11 (didn't work on 3.1.10 either) and have no idea why it doesn't work


Code:
https://www.mydomain.com/welcome/index

https://www.mydomain.com/index.php/welcome/index

https://www.mydomain.com/index.php?/welcome/index


These URL are working fine directly from browser no problem with them.

Now I need to rewrite some existing static pages to codeigniter controllers. In this case just for testing codeigniter welcome page. First of all to make sure RewriteRule works as expected I tested it with a regular php file i created. And it works fine. Remember I need rewrite not redirect.

Code:
RewriteRule ^(staticpage_(?:\d+)\.html)$ myphpcode.php [L]


Code above is working fine.

Problem is when i try codeigniter instead of myphpcode.php

If I try lines below all of them returns Codeigniter's Page Not Found error.

Code:
RewriteRule ^(staticpage_(?:\d+)\.html)$ /welcome/index [L]
Code:
RewriteRule ^(staticpage_(?:\d+)\.html)$ index.php/welcome/index [L]
Code:
RewriteRule ^(staticpage_(?:\d+)\.html)$ index.php?/welcome/index [L]


If I set enable_query_strings to TRUE rewrite works but I don't want to enable it. Also config documentation clearly says that

Please note that some of the helpers won't work as expected when this feature is enabled, since CodeIgniter is designed primarily to use segment based URLs.

Any other way to rewrite existing static content to codeigniter controllers?


RE: .htaccess RewriteRule doesn't work as expected - Wouter60 - 10-02-2019

Which url is visible in your browser?
What is the value of $config['base_url'] in application/config ?
Does your welcome controller have a function named "index"?


RE: .htaccess RewriteRule doesn't work as expected - ergec - 10-02-2019

(10-02-2019, 05:47 AM)Wouter60 Wrote: Which url is visible in your browser?
What is the value of $config['base_url'] in application/config ?
Does your welcome controller have a function named "index"?




All these three are visible in browser



Code:
https://www.mydomain.com/welcome/index
https://www.mydomain.com/index.php/welcome/index
https://www.mydomain.com/index.php?/welcome/index




Base url is







Code:
$config['base_url'] = 'https://www.mydomain.com/';




Yes welcome controller is the default one that comes with codeigniter and has index method. It displays the standard welcoming message of codeigniter. See attachment.