Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter and Javascript url-rewriting clash

My project is setup in CodeIgniter. To cleanup CI's url I added a RewriteRule to the htaccess of the page which removes the ugly 'index.php':

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

This rule rewrites:

https://baseurl/index.php

to

https://baseurl/

Now, I also want to use javascript deeplinking, because the project relies heavily on Ajax page refreshes. The deeplink looks like this:

https://baseurl/#/deeplink

Problem is: The rewrite rule deletes my beatifully injected deeplink and redirects the user to the root site... How can i get rid of the index.php without deleting my deeplink on a hard page refresh?

Thanks!

Dave Timmerman

like image 720
Zukzuk Avatar asked Feb 22 '26 23:02

Zukzuk


1 Answers

The fragment #/deeplink is never sent to the server, URL fragments are kept around only on the client's end (the browser). It's never sent to the server as part of the request. The request:

https://baseurl/#/deeplink

Looks no different to the index.php script than:

https://baseurl/

Not sure how you were ever able to read the fragment on the server to begin with.

like image 89
Jon Lin Avatar answered Feb 25 '26 11:02

Jon Lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!