1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to use the INCLUDE function on .htm pages?

Discussion in 'PHP' started by Mr.Dog, Apr 3, 2013.

  1. tasos55

    tasos55 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #21
    you're right
     
    tasos55, Apr 8, 2013 IP
  2. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #22
    :p Well, I've been using iframes before, I'm trying to use new techniques. PHP is so much more sophisticated and seems to load faster.
     
    Mr.Dog, Apr 9, 2013 IP
  3. edduvs

    edduvs Well-Known Member

    Messages:
    394
    Likes Received:
    31
    Best Answers:
    3
    Trophy Points:
    160
    #23
    Generally speaking, static websites don't require PHP. (Pre-Hypertext-Procesor). Logics made simple, compare Pre-Hypertext-Processor to HyperText Markup Language and you'll understand the point of PHP in HTML just reading that "Pre". Because it works with data before page is shown, then it renders the final HTML.
     
    edduvs, Apr 10, 2013 IP
  4. ChiragKalani

    ChiragKalani Active Member

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    73
    #24
    There is one easy solution for your making page SEO friendly. You can show your php page as html or htm to User/Browser. For that, It require to edit .htaccess file in your server.

    Put below code in .htaccess file


    RewriteEngine on
    RewriteRule ^(.*)\.html$ $1.php [nc]


    For making this work, you need to enable the mod_rewrite extension.

    You also have to change the links in Web page.
    For example, You can call index.php in browser using index.html.

    Let me know if this helps you or have any queries.

    Thanks,
     
    ChiragKalani, Apr 10, 2013 IP
  5. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #25
    Now basically I will have HTML-written pages, but saved as .php, because they will contain 2-3 php scripts in them, each.

    I think this is all right now.

    I don't want to rewrite the .php extension to .htm
    What I want is to eliminate the .php from the end... not sure how I can do this, I tried several codes, but they didn't show any results.

    I don't want redirection, but extension (.php) eliminated.

    Of course, I would also like to eliminate the "index.php" pages, so that they don't show up. They should appear:

    http://www.mysite.com
    http://www.mysite.com/topicone

    instead of:

    http://www.mysite.com/index.php
    http://www.mysite.com/topicone/index.php
     
    Mr.Dog, Apr 12, 2013 IP
  6. ChiragKalani

    ChiragKalani Active Member

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    3
    Trophy Points:
    73
    #26
    Rewrite is good solution if you can implement that. Because users never come to know that this page is actually PHP.

    You can also eliminate the index.php using rewriting.
     
    ChiragKalani, Apr 12, 2013 IP
  7. edduvs

    edduvs Well-Known Member

    Messages:
    394
    Likes Received:
    31
    Best Answers:
    3
    Trophy Points:
    160
    #27
    @Chirag, you didn't even bother answering OP's question, as I'm reporting your post for post hunting / offtopic.

    @Mr. Dog, try this in your .htaccess
    The line with !-d checks that it's not a directory, the line with -f checks that the requested file is a .php file.
     
    edduvs, Apr 12, 2013 IP
  8. Nullifi3d

    Nullifi3d Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #28
    You do realize that extension of a file has NO affect on SEO?
     
    Nullifi3d, Apr 12, 2013 IP
  9. edduvs

    edduvs Well-Known Member

    Messages:
    394
    Likes Received:
    31
    Best Answers:
    3
    Trophy Points:
    160
    #29
    Actually you're wrong, you make the bot's life easier. It doesn't need to loop that string and strip the title anymore.
     
    edduvs, Apr 12, 2013 IP
  10. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #30

    It looks good and that's why I want to change it. Also: when sharing an URL, people like it more if it's without an extension.

    I have .php and .htm files, other sites use .html... sometimes people mistype...

    edduvs: will try that code later today, what I've tried by myself didn't work at all... not sure if there's some server setting blocking it or what...
     
    Mr.Dog, Apr 14, 2013 IP
  11. edduvs

    edduvs Well-Known Member

    Messages:
    394
    Likes Received:
    31
    Best Answers:
    3
    Trophy Points:
    160
    #31
    Mr. Dog , just copy paste the code into .htaccess file.
     
    edduvs, Apr 14, 2013 IP
  12. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #32
    I know that, mate! :p
    Just haven't been in office for a while...
     
    Mr.Dog, Apr 15, 2013 IP
  13. Nullifi3d

    Nullifi3d Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #33
    Just so you know, the extension does not matter for the default/index file that displays when visiting a directory..... So if you visit www.domain.com/pvpvshtml/ then your default file will display regardless of file extension. Your insights are uneducated, imo; perhaps you need to do more research before implementing what you think is the best way.

    Anyways... nobody should be typing the full path to a specific file anyways. People use hyperlinks, shortcuts and bookmarks to navigate websites.
     
    Nullifi3d, Apr 15, 2013 IP
  14. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #34
    I tried using this for .htm extensions, but it's not working...

    I created a fresh new (blank) .htaccess file in notepad, put this in and uploaded it:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.htm -f
    RewriteRule ^(.*)$ $1.htm
    Code (markup):
    Still not working.

    The .htaccess file is on the root folder, where my site's index.htm file is located... perhaps the location is not right?
     
    Mr.Dog, Apr 15, 2013 IP
  15. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #35
    This might be a stupid question, but are you sure your hosted on Apache? .htaccess doesn't work on other types of server software. If it's nginx or IIS -- it's not gonna work.
     
    deathshadow, Apr 15, 2013 IP
  16. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #36
    Right! I will contact my hoster... I manage so many sites, I actually forgot about Apache...
     
    Mr.Dog, Apr 16, 2013 IP
  17. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #37
    ...it's an Apache server and they're saying it has to be rewritten.

    I've used similar codes a few days ago and those didn't work either.

    I have the upper code in the .htaccess page, which is in the root public_html folder.

    The .htaccess only contains this code, nothing else. I created it from a blank Notepad page.

    Can't see the reason why it's not working, but I have no experience in how to write these .htaccess codes.
     
    Mr.Dog, Apr 16, 2013 IP
  18. Nullifi3d

    Nullifi3d Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #38
    Mod Rewrite - look it up

    IDK what I am talking about though; I am only a webhost myself...
     
    Nullifi3d, Apr 16, 2013 IP
  19. Mr.Dog

    Mr.Dog Active Member

    Messages:
    912
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #39
    Well, right now I used this code for removing the .htm extension, this time I tried ".htm" and also with ".html" in the code, but didn't work:

    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(([^/]+/)*[^./]+)/$ $1.html
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    
    Code (markup):
    .htaccess is right on the root where my index.htm file is...

    I also tried with this code:


    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.htm -f
    RewriteRule ^(([^/]+/)*[^./]+)/$ $1.htm
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]


    This code isn't working either...

    I cleared my cache, tried different browsers. It's not propagating.
     
    Mr.Dog, Apr 18, 2013 IP
  20. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #40
    You're getting too complex -- though I would question if htaccess is even enabled. Is your hosting running cPanel? Misconfigured that can raise all sorts of hell...

    Idea... try JUST THIS in a .htaccess, it's the one I use for my pages:

    RewriteEngine On
    RewriteRule !\.(gif|jpg|png|css|js|html|ico|zip|rar|pdf|xml|mp4|mpg|flv|swf|mkv|ogg|avi|woff|svg|eot|ttf|jar)$ index.php
    Code (markup):
    The above rule is a whitelist -- files of the above extensions are served normally -- those NOT using the above extensions are routed to test.php

    With this as index.php:
    
    <?php echo $_SERVER['REQUEST_URI']; ?>
    
    Code (markup):
    That should output the URL you tried to access. That's how I handle 'user friendly' URL's -- I just shove the entire request at PHP without trying to play fancy games parsing out the GETDATA in the .htaccess;

    If that doesn't work, then your server isn't configured properly or you're doing something REALLY wrong.

    In production I just extract the getdata from the original request as provided in $_SERVER. You can even use $_SERVER['PHP_SELF'] to help parse it out.



    
    function cleanPath($path) {
    	return str_replace(array('\\','%5C'),'/',$path);
    }
    
    $url=cleanPath($_SERVER['REQUEST_URI'], 1);
    if (strpos($url,'../')) die('Uptree link in URI');
    $offset = strlen($_SERVER['PHP_SELF']) - 9;
    $end = ($end == strpos($url,'?')) ? $end - $offset : 4096;
    $url = substr($url,$offset,$end);
    $request = empty($url) ? array('default') : explode('/',$url);
    
    Code (markup):
    The cleanpath function is there to prevent Windows vs. IE slashes. The minus 9 on PHP_SELF's length is the length of 'index.php' -- which doing this should always give you the root URI.
     
    deathshadow, Apr 18, 2013 IP