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 5 of 5
  1. #1
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1

    Rewrite url to take contents from a specific direcory?

    Hello,

    I've just modified the html layout of a website and I would like to keep all the new files in a directory to keep the previous contents also

    So I just created a directory named 22-Jan-2008 and put all files in to it.
    Now how can I write a RewriteRule to address this directory when someone tries www.example.com
    Something like
    Code:
    RewriteRule %{HTTP_HOST}$ %{HTTP_HOST}/22-Jan-2008/ [L]
    is possible?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    RewriteCond %{HTTP_HOST} ^www.example.com/.*
    RewriteRule ^/(.*)$ /22-Jan-2008/$1 [L]
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    abduraooft (01-23-2008)

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Thanks shyam, but working partially.

    I already have an htaccess in the root with
    Rule 1
    Code:
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    and
    Quote Originally Posted by shyam
    RewriteCond %{HTTP_HOST} ^www.example.com/.*
    RewriteRule ^/(.*)$ /22-Jan-2008/$1 [L]
    doesn't work as such. So I used just
    Rule 2
    Code:
    RewriteRule ^(.*)$ 22-Jan-2008/$1 [L]
    and now it looks for contents in the subfolder rather than root as desired.
    ---------------
    My subfolder contains another htaccess to style the url like
    Rule 3
    Code:
    RewriteRule ^([^/\.]+)$ index.php?page=$1 [L]
    Now the problems are
    1)Users can access the site through www.example.com/22-Jan-2007. Can I prevent this?
    2)www is not get appended when someone types http://example.com/22-Jan-2007. Can I modify my above Rule 1 to inherit the effect to here also?
    3)My index page looks for the url to decide which content to be displayed using
    PHP Code:
    if(!$page=strtolower($_GET['page']))
        
    $page='home';
        ; 
    (which use Rule 3)
    where I have a switch($page) and in the default case I'd like to display a custom 404 message.
    But this doesn't work if someone type www.example.com/22-Jan-2007/blah. Any solutions?

    Sorry If my explanation is too complex. Hope everything is due to some shortage in the rules. I've gone through many articles but didn't get enough grip. Please help.
    Last edited by abduraooft; 01-23-2008 at 03:28 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Finally, I added
    Code:
    ErrorDocument 404 http://www.example.com/error
    ErrorDocument 403 http://www.example/error
    in to my root's htaccess and now all the unwanted urls are nicely catched by the switch($page) block.

    Now the wired problems are when I type www.example.com/22-Jan-2008, it displays the home page, means, user may get the idea that there is such a directory.
    How can I solve this? (Not a big problem, but for self satisfaction )
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Finally, is there any rule to effectively work
    Code:
    RewriteRule Pattern Substitution
    , that there should not be a directory having the name Pattern ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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