+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: .htaccess rewrite engine help

  1. #1
    ryanmm is offline x10Hosting Member ryanmm is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    36

    .htaccess rewrite engine help

    my site is laid out like so:

    public_html/index.php
    public_html/everythingelse/(all other files here)

    Im trying to figure out how to remove everything in the browser's url bar after the .com in my site. so,

    http://mysite.com/everythingelse/blah.php

    would be rewritten as:

    http://mysite.com

    and http://mysite.com/index.php

    would also be rewritten as:

    http://mysite.com

    I also have a fixed ip and ssl, and would like to redirect all traffic to everything except mysite.com/index.php to https. so, everything inside of my everythingelse folder is not accessible via regular http, only via secure https

    anybody know the htaccess rewrite engine well enough to be able to do this?

  2. #2
    MaestroFX1's Avatar
    MaestroFX1 is offline Community Advocate MaestroFX1 has a spectacular aura about
    Join Date
    Feb 2008
    Location
    Area 51
    Posts
    1,577

    Re: .htaccess rewrite engine help

    just remember this : filesystem takes the first precedence

    and "everythingelse" is a directory as you have mentioned above.

  3. #3
    vv.bbcc19's Avatar
    vv.bbcc19 is offline Community Advocate vv.bbcc19 is just really nice
    Join Date
    Jun 2010
    Location
    India
    Posts
    1,505

    Re: .htaccess rewrite engine help

    In Cpanle, you can directly put a redirect so that it writes to .htaccess.or
    I can give you how I do a 301 redirect.That 301 thing should be replaced by your required file.

    Redirect example.com/index.php to example.com/

    Another snippet that I've heard is a good idea to make sure search engines don't give you a duplicate content penalty, this will also redirect example.com/folder/index.php to example.com/folder/.

    Options +FollowSymLinks
    RewriteEngine on
    # index.php to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

    If you need further help,read the following.



    Method 1 - .htaccess 301 Redirect

    The smoothest way to redirect your visitors is to use an .htaccess redirect. This has no delay since before a page is served to the browser the server checks first for an .htaccess file... if it sees this the old page never loads, instead visitors are sent directly to the new page.

    These are a few .htaccess redirect codes that I've used that might come in handy for you. This is not a complete list by any means, but it took me ages to find how to do these so I'll save you the hassle and list them here. Oh, and please don't email me with questions about how these work, like I said, I found these with the help of others.. I have no idea in the slightest how to write this stuff and take no credit (or responsibility) for how they work.
    mportant notes about htaccess redirection

    Always be sure to upload .htaccess files in ascii mode, sending it up as binary will break it (and usually make your server very, very unhappy.)
    .htaccess does not work if you're on a windows server.
    Make sure you triple check your changes. Clear your cache and look, test the server headers to make sure you see a 301 (that means its permanent) not a 302 (temporary) unless you are absolutely sure you really mean temporary.
    Since some operating systems don't allow you to make a file without something before the "." you may need to save it as something.htaccess, some may even have to save it as htaccess.txt and change it once you've uploaded it.
    Make sure your ftp program will show .htaccess files (FileZilla does and is free) It is a bit hard to edit something you can't see ;)
    Double check that you're not overwriting an old one (some servers already place one there for your custom 404 pages etc.)
    Make sure you replace example.com with your own sites URL ;-)

    Examples

    Redirect 301 /oldpage.html http://www.example.com/newpage.html

    or
    Redirect 301 / http://www.example.com/

    Hope this helps
    Regards,
    VVBB
    BCV | Community Support Representative
    █ x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  4. #4
    ryanmm is offline x10Hosting Member ryanmm is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    36

    Re: .htaccess rewrite engine help

    I copied and pasted this into my .htaccess file in public_html.

    Options +FollowSymLinks
    RewriteEngine on
    # index.php to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

    Didnt seem to have any effect.

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: .htaccess rewrite engine help

    The current virtual host setup requires you to set RewriteBase. In your document root, it should be "RewriteBase /".

    Your question doesn't make much sense. You say you want "http://mysite.com/everythingelse/blah.php" and "http://mysite.com/index.php" to be rewritten to "http://mysite.com", meaning anyone who tried to go to either of the first two would wind up at the third. Do you want this rewrite to be external (i.e. result in a redirect)? Since requesting "http://mysite.com" would result in a directory index being returned, you'd have to be very careful not to have a rewrite loop.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  6. #6
    ryanmm is offline x10Hosting Member ryanmm is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    36

    Re: .htaccess rewrite engine help

    There are a couple things im trying to do with the rewrite.
    lets forget the https ssl and just focus on the url shortening

    I want every page in my site to be shortened to just "mysite.com"
    it is my understanding that shortening urls doesn't actually redirect the user anyway, and to the server, the long url
    like "mysite.com/user/comp.php?ID=3678764&time=209894" will both still exist and be the page that is actually served to the user,
    the only thing that happens is that apache changes the way the url appears in the clients browser.
    So the server sees and understands and works with "mysite.com/user/comp.php?ID=3678764&time=209894"
    and the user sees whatever is on the page "mysite.com/user/comp.php?ID=3678764&time=209894"
    the only thing that has changed is the url in the browsers url bar or text field or whatever you call it,
    will read "http://mysite.com"
    so no, its not a redirect, unless i am confused, which has been known to happen, lol

    as for RewriteBase, I'm not sure what you mean by document root.
    would this work?:

    RewriteBase /
    Options +FollowSymLinks
    RewriteEngine on
    # index.php to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
    Last edited by ryanmm; 03-31-2011 at 11:36 AM.

  7. #7
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: .htaccess rewrite engine help

    That is not how rewrites work.

    Url on the page example.com/foodle/boodle

    click on it, and that is the URL that will stay in the address bar.

    Rewrite can take /foodle/boodle and look internally for /boodle/foodle.php and return that, but the URL in the address bar will not change.

    The only way you can make the address bar change is issue a redirect. But if you redirect to example.com , you loose /foodle/boodle and you just end up on the front page. If you redirect to example/boodle/foodle.php , that is what will end up in the address bar.

    If you really want the address bar to read example.com for all your pages, use frames. The content of the display frame will change while the address bar will stay at the address of the parent frame.
    Nothing is always absolutely so.

  8. #8
    ryanmm is offline x10Hosting Member ryanmm is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    36

    Re: .htaccess rewrite engine help

    hmmmm, so this guy just has no idea what he's talking about:

    "not-so-simple rewriting ... flat links and more
    You may have noticed, the above examples use regular expression to match variables. What that simply means is.. match the part inside (.+) and use it to construct "$1" in the new URL. In other words, (.+) = $1 you could have multiple (.+) parts and for each, mod_rewrite automatically creates a matching $1, $2, $3, etc, in your target (aka. 'substitution') URL. This facility enables us to do all sorts of tricks, and the most common of those, is the creation of "flat links"..

    Even a cute short link like http://mysite/grab?file=my.zip is too ugly for some people, and nothing less than a true old-school solid domain/path/flat/link will do. Fortunately, mod_rewrite makes it easy to convert URLs with query strings and multiple variables into exactly this, something like..

    a more complex rewrite rule:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^files/([^/]+)/([^/]+).zip /download.php?section=$1&file=$2 [NC]

    would allow you to present this link as..

    http://mysite/files/games/hoopy.zip

    and in the background have that transparently translated, server-side, to..

    http://mysite/download.php?section=games&file=hoopy

    which some script could process."


    from:
    http://corz.org/serv/tricks/htaccess2.php
    Last edited by ryanmm; 03-31-2011 at 01:39 PM.

  9. #9
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: .htaccess rewrite engine help

    I don't see anything in that which relates to what you want.
    Nothing is always absolutely so.

  10. #10
    ryanmm is offline x10Hosting Member ryanmm is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    36

    Re: .htaccess rewrite engine help

    look at the middle 2 links..

    he completely changes everything after http://mysite/
    Last edited by ryanmm; 03-31-2011 at 01:46 PM.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. .htaccess MOD REWRITE
    By DarkDragonLord in forum The Marketplace
    Replies: 6
    Last Post: 04-26-2011, 02:07 AM
  2. Htaccess url rewrite
    By cartermcpyro in forum Free Hosting
    Replies: 0
    Last Post: 03-06-2010, 10:01 AM
  3. Rewrite engine problem
    By xav0989 in forum Programming Help
    Replies: 2
    Last Post: 12-06-2008, 09:45 PM
  4. Need help with Htaccess mod-rewrite
    By Mumin in forum Programming Help
    Replies: 2
    Last Post: 06-23-2008, 04:02 PM
  5. .htaccess rewrite rule
    By theblazingangel in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 03-03-2006, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers