Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other htaccess

  • This topic is empty.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #34878
    lily
    Member

    I want to do 4 things to my website,

    1. Redirect html to php
    2. Redirect newyorkbydesign.com to http://www.newyorkbydesign.com
    3. Have clean urls, such as, http://www.newyorkbydesign.com/portfolio/ instead of http://www.newyorkbydesign.com/portfolio.php, for all my webpages
    4. Is there a way to hide, limit access, and/or limit viewing, to subfolders, such as script folders, note or image folders, etc.?

    This is what I have so far, but I know I’m incorrect. I’m new at this end of webdesign, could someone help fix me up? Thank so much for any help.

    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^newyorkbydesign.com
    RewriteRule (.*) http://www.newyorkbydesign.com/$1 [R=301,L]
    RewriteRule ^(.+).html$ http://www.newyorkbydesign.com/$1.php [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php

    #89540
    standuncan
    Member

    As far as #1 goes, do you mean rewrite the extension just so it shows .html instead of .php, or actually redirect about.php to a new separate about.html document?

    #2 http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/#red2

    #3 ?

    #4 http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/#sec3

    #89565
    lily
    Member

    Sorry I’m terrible at the explanation.

    In my site, I started out with,
    for example the page; newyorkbydesign.com/about.html

    Then changed to http://www.newyorkbydesign.com/about/.php

    In the end want to show http://www.newyorkbydesign.com/about/
    in the address bar

    Redirecting each page to the www. address, redirecting the html’s to the php’s instead, and with the extension not showing in the end.

    I hope that explains it better, it’s a real site, so you could actually see the pages and where I’m at with the coding and htaccess. I know it needs help, I don’t have this down yet.

    Thanks so much for the help!

    #89566
    lily
    Member

    So StanDuncan,

    I’ve got the pages to redirect from the non-www to the www, but I don’t have the rest of the coding right I’m sure. Is it because I have the order of the RewriteCond and RewriteRule messed up? Or am I off completely with the rest after the first RewriteRule above in my fist post?

    Thanks

    #89568
    lily
    Member

    Actually I think I have the rediect from non-www to www and the redirect from html to php right. I tried it and it seems to be working. I don’t have the last part though, cleaning up the url to leave out the extension.

    I typed in the address bar

    newyorkbydesign.com/about.html and came out with,

    http://www.newyorkbydesign.com/about.php

    now if I could just get it to show without the pesky extension, that would be great!

    Thanks

    #89569
    lily
    Member

    StanDuncan, I’m checking out the links you put in your post for me, I figured I wouldn’t attempt the fourth request until I understand the others fully, first.

    #89572
    standuncan
    Member

    I’m not an .htaccess expert by any means, but if I understand what you’re are wanting to do correctly, I would be using 301 redirects from your old .html pages, to your new .php pages, this will be better for SEO as well.

    Than you will use the mod_rewrite command to remove your php extensions, as long as your host allows this, it’s an apache server and mod_rewrite is enabled, which it sounds like it is already.

    Here is one .htaccess example:



    Options +FollowSymlinks
    RewriteEngine on
    # If requested URL-path plus ".php" exists as a file
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    # Rewrite to append ".php" to extensionless URL-path
    RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

    redirect 301 /index.html http://www.domain.com/index.php
    redirect 301 /about.html http://www.domain.com/about.php

    However, after you get the extensions removed remember to go back into all your files and remove the .php from any links, so your navigation might appear as

    nav.php





    Also if that one mod_rewrite rules does not work, here are two more to try. Some times they work on sites I work on, sometimes they don’t depending on the host:

    https://css-tricks.com/forums/discussion/13851/a-more-in-depth-look-at-mod_rewrite-.htaccess-rules#Item_7

    #89573
    lily
    Member

    It works up until the extension still showing, so I’m going to check out the other link you show above. Could it have something to do with the hosting site, GoDaddy?

    #89574
    lily
    Member

    Your htaccess code is much neater and better than mine, by the way. Mine is very rudimentary!

    #89575
    lily
    Member

    Well, I don’t know not one of them worked. I read those posts, I agree with you it does seem simple enough, by why doesn’t any code to get rid of the extensions work?

    #89576
    lily
    Member

    Is it a symlink thing? Do I have to put everything into subdirectories. Wouldn’t a subdirectories add unnecessary re-routing, like over the river and through the woods to get to a file? I would think (though I know very little!), but I do not know.

    Thanks for helping me, still!

    #89585
    standuncan
    Member

    If none of those versions worked, I can’t help beyond that. On Godaddy, I have to deal with them often, half the time those work, half the time they don’t. Only pattern I have noticed is if the site is in the root of the hosting plan or not, I think that is why. However if the .htaccess is in the root of web directory, it shouldn’t matter. Sorry I can’t help more..

    #89611
    lily
    Member

    Oh, well thanks so much for trying, I appreciate the time and effort.

    My .htaccess file is in the root directory of my site files. I was wondering if you’ve noticed this also with, your files on the server, if I look through the Godaddy hosting FTP I can see another folder in the remote directory; /stats/. In that directory is a blank .htaccess file that I can download, I can update it, but the Godaddy hosting transfer doesn’t allow it to be uploaded. That /stats/ folder also doesn’t show in the ftp file management section at all, nor does it show when I up/download from Dreamweaver.

    One last question, albeit it ay be a dumb one, how do I know if my site is in the root of the hosting plan or not?

    #89617
    standuncan
    Member

    Just ask your hosting company where your root folder is. Usually it is called public_html, www, web, root, etc.

    As for as Godaddy goes, I can’t stand them. They try to limit and block so many options it seems like. Yes I have noticed that folder, I just leave it alone usually.

Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘Other’ is closed to new topics and replies.