Welcome to WebmasterWorld Guest from 54.205.251.179

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

.html to .php - .htaccess. again ;-(

need to switch - but only for root directory

   
2:49 pm on May 30, 2006 (gmt 0)

10+ Year Member



Yet another one with .htaccess problems. I want to switch all my .html pages to .php and for certain reasons I can't parse html pages as php. Basically this works fine for me:

Options +FollowSymlinks
rewriteengine on
rewriterule ^(.+)\.html$ [mydomain.com...] [r=301,nc]

However, this means that all my pages are going from html to php while I still have some subdirectories that I can't switch now. How would the .htacess file have to look then?

Also, I'm still using this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule ^(.*)$ [mydomain.com...] [R=permanent,L]

to make everyone typing [mydomain.com...] being automatically taken to [mydomain.com....]
Is there a way to make both work at the same time?

Thanks!

3:34 pm on May 30, 2006 (gmt 0)

5+ Year Member



You can stick both sets of code that you mentioned in your top-level .htaccess file but I don't think that you can shorten the two into one function (except for removing one instance of "RewriteEngine on").

As for subdirectories, I think you'll have to put an .htaccess file in each of them with similar code to what you already use, but specific to that directory, e.g.


Options +FollowSymlinks
rewriteengine on
rewriterule ^subdirectory/(.+)\.html$ http://www.mydomain.com/subdirectory/$1.php [r=301,nc]
3:40 pm on May 30, 2006 (gmt 0)

10+ Year Member



Thanks, barns101. It seems though that

Options +FollowSymlinks
rewriteengine on
rewriterule ^(.+)\.html$ [mydomain.com...] [r=301,nc]

would change all html's into php's. For example I have a link from my main page to [mydomain.com...] which also gets changed into [mydomain.com...] This is what I have to avoid since I can't yet change the html files in some of my subdirectories.

5:06 pm on May 30, 2006 (gmt 0)

5+ Year Member



To convert only top-level files you could probably use:


rewriterule ^mydomain.com/(.+)\.html$ http://www.mydomain.com/$1.php [r=301,nc]