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 04-30-2008, 02:28 PM   PM User | #1
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
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
htaccess, to catch all possible 404 requests, without ErrorDocument directive.

Hi friends,

I've been trying to make a model/view structure for a website (or the aedrin's method ), so my root directory structure is
Code:
 
 model/
 view/
 common/
 classes/
 css/
 downloads/
 images/
 javascript/
 
 index.php
 .htaccess
I've
Code:
RewriteRule ^([^/\.]+)(/*)([^/\.]*)$ index.php?page=$1&rest=$3 [L]
in my htaccess, which will convert all links like /about, /contact to ?page=about, ?page=contact and so on.

And my index.php contains
PHP Code:
$page=trim($_GET['page']);
if(
$page=="" || $page=="index.php")
    
$page='home';
$general_pages=array("home","about","contact","contact_webmaster");

if(!
in_array($page,$general_pages))
    
$page="404";


include(
"model/{$page}.php");
include(
"common/header.php");
include(
"common/nav.php");
@include(
"view/{$page}.php");
include(
"common/footer.php"); 
The above code also works for /download/file1 to download a file named file1 (I've the required code in /model/download.php, $file=$_GET['rest']; .........)

Now, this setup works fine for all /blah-blah type links, which will show a text in the /view/404.php
Code:
<p> Sorry, the requested page is not found in site. In case, if you have followed a valid link,
please <a href="/contact_webmaster/page=blah-blah&rest=">let know the Majlis webmaster</a>.
</p>
and thus I can catch the requested url in my contact_webmaster form.

Now my question are
  1. Can I catch requests (by modifying htaccess) like /about.php, /blah.blah etc.(currently showing an apache 404 error) in my index.php and pass through the rest of codes?
  2. How can I restrict request like /model/about.php, /view/about.php etc. which is currently displaying a php error or some html with no styles

Hope my questions are clear.
After all sorry for this huge post and thank you for reading the same (I've no other way to explain)

regards,
raoof.
__________________
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; 05-01-2008 at 08:48 AM..
abduraooft is offline   Reply With Quote
Old 05-01-2008, 08:58 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
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
Can I catch everything after my domain name to a variable?
Something like
Code:
RewriteRule ^(.*)$ index.php?page=$1 [L]
?

Unfortunately the above one is not working :-(
Please correct me if I'm wrong.

thanks.
__________________
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 05-02-2008, 05:11 PM   PM User | #3
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
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
120 views... no reply :-(
I must be doing very stupid . Hope my questions were clear.

For the time being when I added
Code:
ErrorDocument 404 /view/404.php
I could manage to show a page with no style and a link to the contact_webmaster page for requests like /blah.blah

And when I added
Code:
RewriteRule ^(model|view|classes)/(.*)$ index.php?page=$2 [L]
to the above, I think, my problem is solved for about 90% (rest 10 for unidentified problems and for the inability to track the requested page in some cases)
__________________
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 05-05-2008, 10:15 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
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
Hmm.. this thread is going to be an addition to my other thread (101 ways to post....)

OK, now a different question..
Can I simplify
Code:
RewriteRule ^tax_exemption$ /view/tax_exemption.php  
RewriteRule ^staff_details$ /view/staff_details.php 
RewriteRule ^affiliation_details$ /view/affiliation_details.php 
RewriteRule ^map_location$ /view/map_location.php

RewriteCond %{REQUEST_FILENAME} !tax_exemption
RewriteCond %{REQUEST_FILENAME} !staff_details
RewriteCond %{REQUEST_FILENAME} !affiliation_details
RewriteCond %{REQUEST_FILENAME} !map_location
RewriteRule ^(model|view|classes)/(.*)$ index.php?page=$1&rest=$2
The idea is I've some pages which are decided to open as popups. So they don't have no common header/footer/nav blocks like other pages have. So I just placed them inside the view/ folder with full document structures.

I'd already restricted access to all files inside this directory via direct urls, but I need to allow this specific cases.

The above rules work as desired, but can I simplify this?
Any help would be much appreciated.

thanks
__________________
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 12:41 AM.


Advertisement
Log in to turn off these ads.