Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-22-2008, 01:37 PM   PM User | #1
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-22-2008, 05:33 PM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
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
shyam is offline   Reply With Quote
Users who have thanked shyam for this post:
abduraooft (01-23-2008)
Old 01-23-2008, 03:22 PM   PM User | #3
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

Last edited by abduraooft; 01-23-2008 at 03:28 PM..
abduraooft is offline   Reply With Quote
Old 01-24-2008, 09:59 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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 )
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-30-2008, 07:46 AM   PM User | #5
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Finally, is there any rule to effectively work
Code:
RewriteRule Pattern Substitution
, that there should not be a directory having the name Pattern ?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:21 AM.


Advertisement
Log in to turn off these ads.