Dragen Posted August 27, 2007 Share Posted August 27, 2007 okay.. I know this is simple to do, but I just can't figure it out. I'm trying to mod-rewrite my .php file extensions to .html, or anything for that matter. I've seen examples so many time, but I just can't find any now I'm wanting them Can anyone point me in the right direction for a mod re-write to change file extensions in the url? thanks Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/ Share on other sites More sharing options...
trq Posted August 27, 2007 Share Posted August 27, 2007 Are you asking how to process .html files as though they where .php? You don't need mod_rewrite for that. Add the following to your .htaccess file. AddType application/x-httpd-php .php .html Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335373 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Author Share Posted August 27, 2007 no, I'm using .php files. in the url it says something like: www.mydomain.com/index.php I want to change it to say: www.mydomain.com/index.html But still using the php files... Is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335376 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Author Share Posted August 27, 2007 Okay.. what I've got is this: RewriteEngine on RewriteRule ^([a-z]+).html$ .php which will get any .hml file from the url.. such as http://www.mydomain.com/index.html and transfer it to: http://www.mydomain.com/.php Obviously not quite right... how do I get it to keep the page name (i.e 'index') so that I can use it for the rewrite? Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335405 Share on other sites More sharing options...
trq Posted August 27, 2007 Share Posted August 27, 2007 Something like... RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*).html$ $1.php [L] will direct index.html to index.php, home.html to home.php etc etc. Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335410 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Author Share Posted August 27, 2007 thanks! I've just been searching more and came up with this, which seems to work: RewriteEngine on RewriteRule ^([a-z0-9]+).html$ $1.php what does the following snippets of code do? !-f !-d $1 I don't know what the $1 does, but it seemed to work... thanks Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335414 Share on other sites More sharing options...
trq Posted August 27, 2007 Share Posted August 27, 2007 The part between the braces ([a-z0-9]+) is captured and placed within $1. Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335423 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Author Share Posted August 27, 2007 okay, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335428 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Author Share Posted August 27, 2007 Thanks for helping... can I make the mod rewrite only effect urls which don't include certain words? such as 'reg'. so this url would get re-written: mydomain.com/myfile.html but this wouldn't: mydomain.com/myfilereg.html Quote Link to comment https://forums.phpfreaks.com/topic/66901-mod-rewrite-filetype/#findComment-335445 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.