Jelte Posted November 8, 2012 Share Posted November 8, 2012 Hello everybody, This is one of my first times that i need to configure a .htacces file, so maybe is this a very simple question but I cant figure it out by myself . Situation: I have a local site, that reachable under the URL: "framework.dev". But I need to configure a rewrite rule: rewrite all the URL's to index.php, except the exact URL: 'framework.dev'. example: framework.dev/users //Rewrite this url to index.php framework.dev/users/edit/1 //Rewrite this url to index.php framework.dev/login //Rewrite this url to index.php etc.. framework.dev //Do not rewrite How do i formulate the correct .htacces rewrite rule? Thank you for you time, Greetings Jelte PS: I you know a good .htaccess tutorial please inform me Link to comment https://forums.phpfreaks.com/topic/270474-htaccess-do-no-rewrite-a-specific-url/ Share on other sites More sharing options...
requinix Posted November 8, 2012 Share Posted November 8, 2012 Think of it in a slightly different way: don't rewrite /index.php, do rewrite everything else to /index.php. Note how the domain name doesn't matter (unless you want it to). RewriteRule ^index.php - [L] RewriteRule ^ index.php [L] Or I think you might actually want to be rewriting anything that doesn't exist, that way images and CSS and those things will be served correctly. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] Link to comment https://forums.phpfreaks.com/topic/270474-htaccess-do-no-rewrite-a-specific-url/#findComment-1391173 Share on other sites More sharing options...
Jelte Posted November 9, 2012 Author Share Posted November 9, 2012 Thanks for your comment, I am afraid that is doesn't do the trick, i tested it and know framework.dev/test is unreachable (404 error) But i think of another aproach, like you say the domain doenst matter, but we can check the request_uri. When i go to framework.dev the request_uri is: /. and if i go to framework.dev/user the request_uri is: /user. So i need the condiction for the following statement: if request_uri is not equal to '/' then redirect to index else do no redirect. Thanks for your help! Greetings jelte. Link to comment https://forums.phpfreaks.com/topic/270474-htaccess-do-no-rewrite-a-specific-url/#findComment-1391187 Share on other sites More sharing options...
requinix Posted November 9, 2012 Share Posted November 9, 2012 I generally don't spell it out but maybe I should: Did you include the RewriteEngine directive? It's necessary for absolutely anything having to do with mod_rewrite so I hardly ever bring it up (it's implied and I assume people have already done enough research to know that). The complete example, with a small modification, is RewriteEngine on RewriteRule ^/?index.php - [L] RewriteRule ^ index.php [L] RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] Link to comment https://forums.phpfreaks.com/topic/270474-htaccess-do-no-rewrite-a-specific-url/#findComment-1391200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.