unemployment Posted August 30, 2012 Share Posted August 30, 2012 I'm in the process of trying to build a single page application and I need to rewrite all my page to the index.php file, but I'm not sure how to do it. When I try with the code below, all of my script files break. Any suggestions? RewriteRule ^(.*)$ index.php?page=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/267787-rewrite-all-pages-to-index-kils-all-javascript/ Share on other sites More sharing options...
requinix Posted August 30, 2012 Share Posted August 30, 2012 Make it only rewrite if the requested file doesn't exist. Before the RewriteRule put RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Quote Link to comment https://forums.phpfreaks.com/topic/267787-rewrite-all-pages-to-index-kils-all-javascript/#findComment-1373763 Share on other sites More sharing options...
unemployment Posted August 30, 2012 Author Share Posted August 30, 2012 Make it only rewrite if the requested file doesn't exist. Before the RewriteRule put RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d That fixed the script errors I was having but this isn't exactly functioning perfectly. Right now if I go to index it works great and if I use Javascript (Backbone.js) to load my next view and navigate to the next page with the HTML5 History API, that works. The problem is when loading a page that has a query string. For instance, if I go to index/login, the page redirect back to index and then my JS will load the login view. This is not what I want to have happen. It is essentially causing the screen to flicker since it loads the index first and then the JS view. Not sure how to solve this. Quote Link to comment https://forums.phpfreaks.com/topic/267787-rewrite-all-pages-to-index-kils-all-javascript/#findComment-1373853 Share on other sites More sharing options...
trq Posted August 30, 2012 Share Posted August 30, 2012 That sounds far more likely to be a JavaScript issue. Quote Link to comment https://forums.phpfreaks.com/topic/267787-rewrite-all-pages-to-index-kils-all-javascript/#findComment-1373889 Share on other sites More sharing options...
unemployment Posted August 30, 2012 Author Share Posted August 30, 2012 That sounds far more likely to be a JavaScript issue. Yeah... I'm actually changing my approach. I was originally think I'd build a single page app, but not I think getting SEO benefit from that is just going to too difficult. I decided on a hybrid approach where I will only use backbone to render application pages and have other pages be generated by PHP Quote Link to comment https://forums.phpfreaks.com/topic/267787-rewrite-all-pages-to-index-kils-all-javascript/#findComment-1373923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.