Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Location
    NY
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Simple Redirection from PHP to HTML

    alright.. well my problem lies in htacess. (I didnt know which forum to post it in)

    anyways.. I have
    http://website.com/about.php

    but I want it to AUTOMATICALLY to be displayed as

    http://website.com/about
    NOT http://website.com/about/ or http://www.website.com/about/

    how can I do this with my .htacess?


    EXAMPLES:
    YES: http://website.com/contact-us
    NO: http://website.com/contact-us.php

    YES: http://website.com/our-services
    NO: http://website.com/our-services.php
    Last edited by theprivl; 02-23-2009 at 04:44 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Location
    NY
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you solution does not solve my problem.

    I need to AUTOMATICALLY redirect all my old links .. to new more SEF/SEO friendly links by simply taking away the extension, and eliminating the "www".

    PS - I spent 5 hours on google. Nothing AUTOMATICALLY redirects. The content below works perfectly.. but it does not REDIRECT the user.. which makes it pretty pointless.

    Code:
     Options +FollowSymlinks
     RewriteEngine on
    
    #  /about.php can be viewed as /about
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME}\.php -f
     RewriteRule ^(.*)$ $1.php
    
    # this removes www from URL
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    # this removes www from URL
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
    Try the following instead for no-www redirect.
    Code:
    RewriteCond %{HTTP_HOST} ^www\.mysite.com [NC]
    RewriteRule ^(.*) http://mysite.com/$1 [L,R=301]
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Location
    NY
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Try the following instead for no-www redirect.
    Code:
    RewriteCond %{HTTP_HOST} ^www\.mysite.com [NC]
    RewriteRule ^(.*) http://mysite.com/$1 [L,R=301]

    ok thanks.. but what about jut hiding the ".php" ?
    Nothing works! I scoured google for the past 2 days.. nothing works!

  • #6
    New to the CF scene
    Join Date
    Nov 2007
    Location
    NY
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    WOW! I got it!
    Code:
    RewriteEngine on
    #
    ## Internally rewrite extensionless file requests to .html files ##
    #
    # If the requested URI does not contain a period in the final path-part
    RewriteCond %{REQUEST_URI} !(\.[^./]+)$
    # and if it does not exist as a directory
    RewriteCond %{REQUEST_fileNAME} !-d
    # and if it does not exist as a file
    RewriteCond %{REQUEST_fileNAME} !-f
    # then add .html to get the actual filename
    RewriteRule (.*) /$1.html [L]
    #
    #
    ## Externally redirect clients directly requesting .html page URIs to extensionless URIs
    #
    # If client request header contains html file extension
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
    # externally redirect to extensionless URI
    RewriteRule ^(.+)\.html$ http://www.example.com/$1 [R=301,L]
    http://www.webmasterworld.com/apache/3371997.htm

  • #7
    New to the CF scene
    Join Date
    Nov 2007
    Location
    NY
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    so here is the final code..


    Code:
    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} !(\.[^./]+)$
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) /$1.php [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
    RewriteRule ^(.+)\.php$ /$1 [R=301,L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
    RewriteRule ^([^.]+)\.html /$1.php [R=301,L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+htm\ HTTP
    RewriteRule ^([^.]+)\.htm /$1.php [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
    here is what it does.. (i think)

    .html ---> .php
    .htm --> .php
    php --> {removes ".php"}
    also ... removes "www"

    EXAMPLE OF USAGE
    Code:
    http://www.example.com/about.html
    http://www.example.com/about.htm
    http://www.example.com/about.php
    http://example.com/about.html
    http://example.com/about.htm
    http://example.com/about.php
    
    ALL AUTOMATICALLY redirect to..
    
    http://example.com/about
    if anyone wants to add on..please do so! .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •