Web Hosting Forums

Results 1 to 5 of 5

This is a discussion on [ot]: mod_rewrite in the Hosting Talk & Chit-chat forum
Sorry, I couldn't find an appropriate forum for this question, so I'm hoping someone here might have had some experience. I thought that I had ...

  1. #1
    Loyal Client
    Join Date
    Mar 2002
    Posts
    34

    [ot]: mod_rewrite

    Sorry, I couldn't find an appropriate forum for this question, so I'm hoping someone here might have had some experience.

    I thought that I had a firm grasp on regular expressions but I can't seem to figure out how to accomplish what I want with mod_rewrite.

    I would like to make it so that, instead of putting files in ~/public_html/, I could put them in ~/public_html/stevenv/ (for example), because I plan on eventually multihosting other domains and it would reduce clutter if all sites went into their own subdirectories.

    Here are some things I've tried (in my .htaccess, of course):

    Options FollowSymLinks Indexes
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*[^/]) stevenv/$1

    AFAIK, $1 should be zero or more of any characters uneless they have a slash (/). i.e. foo.html should match and be sent to stevenv/foo.html, shouldn't it? A slight variant to this one I have tried is:

    RewriteRule ^(.*) stevenv/$1

    This was for testing purposing because I don't want to send all requests into this subdir, only requets for files within my www root. Why didn't .* match foo.html and send it to stevenv/foo.html?

    This one did work for me (although useless):

    Options FollowSymLinks Indexes
    RewriteEngine On
    RewriteBase /
    RewriteRule ^foo.html stevenv/foo.html

    If anyone knows what I'm doing wrong I would really appreciate it, I must have tried atleast a hundred different RewriteRules over the past three days

    thanks
    steven

  2. #2
    young and idealistic clio's Avatar
    Join Date
    Oct 2002
    Location
    Tübingen, Germany
    Posts
    2,140
    request tribby, our resident rewrite expert
    - Julie
    Student / Web Developer

  3. #3
    Loyal Client
    Join Date
    Jul 2001
    Posts
    579
    Originally posted by clio
    request tribby, our resident rewrite expert
    Again?



    stevenv, try this:


    RewriteEngine on

    rewritecond %{HTTP_HOST} ^yourdomain\.com$
    rewritecond %{REQUEST_URI} !^/stevenv/
    RewriteRule (.*) /stevenv/$1

    rewritecond %{HTTP_HOST} ^www\.yourdomain\.com$
    rewritecond %{REQUEST_URI} !^/stevenv/
    RewriteRule (.*) /stevenv/$1


    That should probably succeed in reducing the clutter once you multihost some domains.

  4. #4
    Loyal Client
    Join Date
    Mar 2002
    Posts
    34

    works great :)

    Thanks tribby, that worked great.

    Now I have another question though. Some of my files are going to be straight .html, some are going to be .php. In the future, I might decide to make an .html file a .php file for whatever reason.

    Is it possible, using mod_rewrite, to make it so that I can link to just index (just a file name - no extension), for example and have it check to see whether an index.html or index.php exists?

    If it's not possible using mod_rewrite, I guess I'll go ahead and modify what they have on http://www.alistapart.com/stories/succeed/. ...Or is there another method that I'm overlooking?

  5. #5
    Loyal Client
    Join Date
    Mar 2002
    Posts
    34

    figured it out

    It was a lot easier than I thought All I had to do was add:

    Options MultiViews

    to my .htaccess

    http://httpd.apache.org/docs/content-negotiation.html if anyone wants more info

Bookmarks

Posting Permissions

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