peterisgb Posted May 5, 2014 Share Posted May 5, 2014 Hello, i'm playing around with the .htaccess file. I've got this RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] Which does this to links: http://www.example.com/usersonline.php to http://www.example.com/usersonline Is there a way in the .htaccess file to make all pages display like the above link without editing every link on the site? Quote Link to comment Share on other sites More sharing options...
john. Posted May 5, 2014 Share Posted May 5, 2014 You could try a PERMAMENT REDIRECT in the file. Or just use a proper IDE and change the links. Quote Link to comment Share on other sites More sharing options...
DidNotCompute Posted May 5, 2014 Share Posted May 5, 2014 Hello, i'm playing around with the .htaccess file. I've got this RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] Which does this to links: http://www.example.com/usersonline.php to http://www.example.com/usersonline Is there a way in the .htaccess file to make all pages display like the above link without editing every link on the site? This won't take into account variables in the URL. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted May 5, 2014 Author Share Posted May 5, 2014 well i am completely new to .htaccess files and i hardly know anything about it. Quote Link to comment Share on other sites More sharing options...
wrux Posted May 5, 2014 Share Posted May 5, 2014 You could try using a batch find a replace tool to edit the .php out in every file Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 5, 2014 Share Posted May 5, 2014 If done right in htaccess it won't matter if you have the file extension in the links itself. I believe like what [MENTION=70137]john.[/MENTION] said about a permanent redirect will do just that, it will redirect to the re-written URL to match your regex pattern. Quote Link to comment Share on other sites More sharing options...
wrux Posted May 5, 2014 Share Posted May 5, 2014 If done right in htaccess it won't matter if you have the file extension in the links itself. I believe like what [MENTION=70137]john.[/MENTION] said about a permanent redirect will do just that, it will redirect to the re-written URL to match your regex pattern. I'm assuming you'd use a HTTP302 and this is okay for the shortrun but longterm you'd want to edit links, this is why mccodes needs a url dispatcher Quote Link to comment Share on other sites More sharing options...
peterisgb Posted May 5, 2014 Author Share Posted May 5, 2014 so isnt there a code that i can just stick in .htaccess Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 5, 2014 Share Posted May 5, 2014 Are you trying to rewrite all of your ?'s and &'s? If so your looking at a lot of work. You need to include in your regex all of your query string keys. Or or you can look how wordpress does it but your still looking at a lot of work but since they use a standard they get by fairly easy by doing it with PHP I'm not too savvy with Apache so don't take my word for it Quote Link to comment Share on other sites More sharing options...
peterisgb Posted May 5, 2014 Author Share Posted May 5, 2014 well so far the ? is still there like so viewuser?u=1 instead of viewuser.php?u=1. i dont mind the ?u=1. i just though it would of been easier to use .htaccess to change the link looks instead of going through each page (which will takes for ages) Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 5, 2014 Share Posted May 5, 2014 Not if you use a good IDE Quote Link to comment Share on other sites More sharing options...
wrux Posted May 5, 2014 Share Posted May 5, 2014 Why not have it parse the first bit to the file and after the / you could parse that as a query string... so /user/view/john would get translated into user.php?query=view/john and you can then parse the querystring through a bunch of code that gets the true values Quote Link to comment 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.