|
| |
|
|
Starhugger
Posts: 631 Joined: 4/12/2005 From: Canada Status: offline
|
.htaccess rewrite htm to php - 8/15/2009 14:37:52
I'm redoing my site to use php-includes (instead of the old frontpage-includes). I am planning to place the following code in the .htaccess file so that search engines and linkbacks don't throw a hissyfit when pointing to my site:
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]
My understanding is that this code will convert all requests for *.htm to *.php. As such, I'm renaming all my *.htm files to *.php (whether they use a php-include or not). Three questions: [1] Although I'm doing it anyway to be on the safe side, is it actually necessary to rename all *.htm files on the site to *.php, even if they don't use php code? For example, the included files that are themselves called by a php-include. [2] Will this rewrite code affect outgoing links that access a *.htm or *.html web page? In other words, will it also try to convert those to *.php as well? If yes, is there a way to override this? [3] Where in the .htaccess file should this code go in relation to anything else currently in the file? (I haven't even looked in it yet, but it just occurred to me that I should probably find out.) Thanks for the help! Starhugger
|
|
|
|
noserver
Posts: 1 Joined: 8/24/2009 From: USA Status: offline
|
RE: .htaccess rewrite htm to php - 8/24/2009 1:18:16
asking your hosting provider first are htaccess is allowed or already active or not, second is find some great thread about htaccess code
|
|
|
|
Starhugger
Posts: 631 Joined: 4/12/2005 From: Canada Status: offline
|
RE: .htaccess rewrite htm to php - 8/24/2009 18:29:25
quote:
ORIGINAL: Tailslide I'm no expert at this - always having "issues" but my understanding is that if you use PHP includes in an html page what you need to do is effectively use the .htaccess to supply .html pages as .php pages - so they'll stay as yourpage.html even though they've got php within them. You don't need to change the file extensions at all. Browsers, links, search engines etc still see whatever.html. That's the simple bit. Hi Tailslide! Interesting... My understanding was that it went the other way around -- that I'd need to create PHP pages in order to run PHP code, but that the .htaccess could be trained to take requests for abc.htm(l) and pull up abc.php instead. What you're saying is different -- that I can run PHP code in *.htm(l) files but train .htaccess to treat them like they were *.php files. Truth is, I've already renamed all my files to .php at this point, so I'm not sure if there would be any advantage in going back to rename them back again. If nothing else, Expression Web 2 gets upset when there's PHP code in a HTML file, so that's one reason to keep them .php for now. It doesn't seem to help with the include paths very well unfortunately, but it seems that's probably the lesser of evil options. quote:
...Apache was updated and for some reason it overwrote every single .htaccess file on all my clients' websites!! Ok - says I - no problem - just go in and re-add it. Then about a month later... apache was updated again... you can guess the rest! Oh no! I don't want to hear this. LOL I guess I'll have to be sure to keep a backup, whatever I do. quote:
I found that the best way to do this was to use Cpanel to do it - that way it "sticks". If you have Cpanel - let me know and I'll post a screenshot of what I use to make this work. Yes, I do have Cpanel. Thanks, a screenshot would help, even if I do it the other way around (which was how my host originally suggested I do it), it sounds like it would be better to do it through Cpanel if it's more "sticky." quote:
I'd suggest checking with your host as to what version of apache they're using and what addhandler type to use in your .htaccess file. Last one I used was: AddHandler application/x-httpd-php5 .php .php4 .php3 .phtml .html I'll check with them and post back. Thanks very much! Starhugger
|
|
|
|
womble
Posts: 6009 Joined: 3/14/2005 From: Living on the edge Status: offline
|
RE: .htaccess rewrite htm to php - 8/26/2009 13:40:53
As Tail said, the easiest way to do it is to just use the .php extension for all your pages, which is what I've done as long as I've been using PHP, simply because I never fancied getting into playing around with .htaccess. I only used .htaccess briefly on one site which I switched from plain HTML when I first started using PHP. I use the same host as Tail for all my sites, and the Apache upgrades have never affected any of my sites simply using the .php file extension. As you said, if you've already named your files with PHP, I'd go with that.
_____________________________
~~ "A cruel god ain't no god at all" ~~ ~~ Erase hate. Practice love. ~~
|
|
|
|
BobbyDouglas
Posts: 5525 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: .htaccess rewrite htm to php - 8/26/2009 18:24:56
If you go the route of actually using .php pages, and changing all of your links from .htm to .php, you will want to use .htaccess to issue a 301 redirect for all htm pages to the new php extension. So when you have a page at www.domain.com/page1.htm it will tell the browser that your page has permanently moved to www.domain.com/page1.php This is helpful for not just your everyday users (people who have bookmarked your pages), but Google as well. Google will index the new page since it is a permanent redirect. I like to use FileMonkey when making large extension changes to websites, going from asp to coldfusion, htm pages to php, etc.. You can also send a ticket into your host, and have one of the admins make that change for you.
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
womble
Posts: 6009 Joined: 3/14/2005 From: Living on the edge Status: offline
|
RE: .htaccess rewrite htm to php - 8/31/2009 6:11:26
quote:
ORIGINAL: BobbyDouglas If you go the route of actually using .php pages, and changing all of your links from .htm to .php, you will want to use .htaccess to issue a 301 redirect for all htm pages to the new php extension. That's a good point that Bobby made. I only ever had a problem with one site with one particular host I was with for a while. I changed all my HTML pages to PHP, but I didn't put a 301 redirect on because it was a relatively new site that had only been up a few weeks and was just getting off the ground, and figured that I didn't need to bother with the redirect. It was only some months later though that I accidentally discovered that anyone trying to get to the site by using just the domain name (e.g. www.mysite.com) would get the host's empty "waiting for content" page. Only if they specified a page as well, or www.mysite.com/index.php would they get the site's home page. It must have been something to do with how that particular host's server was set up because I've never had the same problem anywhere else, but I had to put a 301 redirect on index.html to get it to redirect to the PHP page, otherwise if they just used the domain they'd get only the holding page.
_____________________________
~~ "A cruel god ain't no god at all" ~~ ~~ Erase hate. Practice love. ~~
|
|
|
|
Starhugger
Posts: 631 Joined: 4/12/2005 From: Canada Status: offline
|
RE: .htaccess rewrite htm to php - 8/31/2009 11:58:13
Thank you for mentioning that, Womble. I'll have to test that when I get it up and running. SH
|
|
|
|
BobbyDouglas
Posts: 5525 Joined: 5/15/2003 From: Arizona Status: offline
|
RE: .htaccess rewrite htm to php - 9/1/2009 0:03:12
quote:
It was only some months later though that I accidentally discovered that anyone trying to get to the site by using just the domain name (e.g. www.mysite.com) would get the host's empty "waiting for content" page. Only if they specified a page as well, or www.mysite.com/index.php would they get the site's home page. - Just to touch base on this one... That's the DirectoryIndex not being set correctly by your host. Unless you manually set the directory index to be index.htm or index.html, it is a problem with your host. You can tell the server what your default file is supposed to be called for every directory. Sometimes you will see people using weird home page names, such as main.html, or home.html. Within your htaccess, if you set "DirectoryIndex index.htm index.html" it will only display the default page (when you go to a folder) if there is an index.htm or index.html file. Most hosts have it enabled to support all the major index files, starting from most commonly used to least used.
_____________________________
Arizona Web Design - Mr Bobs Web Design in Arizona The Arizona Web Hosting Challenge
|
|
|
|
mindcat238
Posts: 2 Joined: 8/19/2009 Status: offline
|
RE: .htaccess rewrite htm to php - 9/1/2009 5:53:19
This question is too complicated for me
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|