fortnox007 Posted December 4, 2010 Share Posted December 4, 2010 Hi all, I just managed to make a little mod_rewrite rule which manages to interpret url's without the extension and calls the right file with the extension (ie. /articles calls articles.php) . But now i am left with another question which i am almost certain has nothing to do with mod_rewrite, but rather with a php trick. In case someone enters on my site www.mydomain.com/laalalalala.php How do i get rid of that last part(the extension for example)? Do i maybe have to get the GET['var'] and run it through a regex and reload the page with the stripped version? That was all i could think off but it sound so complicated. if anyone has an idea i would love to hear it cheers! P.s.s if anyone want's that rewrite rule, let me know. I saw quite some people on the internet looking for it Quote Link to comment https://forums.phpfreaks.com/topic/220680-stripping-extension-and-more-from-url/ Share on other sites More sharing options...
laffin Posted December 4, 2010 Share Posted December 4, 2010 isnt hat a mod rewrite question? Well mod rewrite should be able to handle that without much problem anyhow Quote Link to comment https://forums.phpfreaks.com/topic/220680-stripping-extension-and-more-from-url/#findComment-1143023 Share on other sites More sharing options...
fortnox007 Posted December 4, 2010 Author Share Posted December 4, 2010 isnt hat a mod rewrite question? Well mod rewrite should be able to handle that without much problem anyhow hmm, you might be right sorry if this is in the wrong forum than Just to make sure i am,.. i want to visually change the address in the browser of the visitor. sorry again if i misplaced it i have this in my htaccess but its not changing anything(visibly), that's why i thought to reload the page with by using getvariables RewriteRule ^([a-zA-Z0-9]+)(/.*)?$ /$1\.php$2 Quote Link to comment https://forums.phpfreaks.com/topic/220680-stripping-extension-and-more-from-url/#findComment-1143024 Share on other sites More sharing options...
requinix Posted December 4, 2010 Share Posted December 4, 2010 By default mod_rewrite will do it invisibly. If you want to actually redirect the browser then add the [R] flag. Like RewriteCond %{REQUEST_FILENAME} -f RewriteRule (^|/)([^/]+)\.php$ $1 [R] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_FILENAME}.php [L] Quote Link to comment https://forums.phpfreaks.com/topic/220680-stripping-extension-and-more-from-url/#findComment-1143030 Share on other sites More sharing options...
fortnox007 Posted December 4, 2010 Author Share Posted December 4, 2010 Oh wow! Thanks a bunch requinix! I'll certainly try that code out looks complicated at first sight but I'am sure it's good to read after a while. Thanks a lot!! Quote Link to comment https://forums.phpfreaks.com/topic/220680-stripping-extension-and-more-from-url/#findComment-1143033 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.