Hello, I am the owner of tackypenguin.com. I have a little problem with my mod rewrite. My .htaccess file says that site.com/user rewrites it to /index.php?page=user. It does that, but then at the bottom of the page, it says: Warning: main(/home/content/r/y/a/ryan/html/user.php): failed to open stream: No such file or directory in /home/content/r/y/a/ryan/html/index.php on line 122 Warning: main(/home/content/r/y/a/ryan/html/user.php): failed to open stream: No such file or directory in /home/content/r/y/a/ryan/html/index.php on line 122 Warning: main(): Failed opening '/home/content/r/y/a/ryan/html/user.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/content/r/y/a/ryan/html/index.php on line 122 Code (markup): How do I take those errors off? On my line 122, it says include("/home/content/r/y/a/ryan/html/$page.php"); PHP:
First, the error message on the site says: ryanwalters not ryan. So, check this first. Second, you don't want to include the file dynamically like this without conditions. You need to make some if conditions (the same as those which generate 404 error on your site) before including the file.
if(file_exists("/home/content/r/y/a/ryanwalters/html/$page.php")) { if(!empty($page)&&empty($do)) { require_once "/home/content/r/y/a/ryanwalters/html/$page.php"; } if(!empty($page)&&!empty($do)) { require_once "/home/content/r/y/a/ryanwalters/html/$page.php?do=$do"; } } else { require_once "404.php"; } PHP: This worked, but if i had /user/login/, my .htaccess says to make it index.php?page=user&do=login. When I do this though, it gives me this error. Warning: main(/home/content/r/y/a/ryanwalters/html/user.php?do=login): failed to open stream: No such file or directory in /home/content/r/y/a/ryanwalters/html/index.php on line 123 Fatal error: main(): Failed opening required '/home/content/r/y/a/ryanwalters/html/user.php?do=login' (include_path='.:/usr/local/lib/php') in /home/content/r/y/a/ryanwalters/html/index.php on line 123 Code (markup): Here is my .htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule ^([a-zA-Z]+)/?$ /index.php?page=$1 RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)?$ /index.php?page=$1&do=$2 </IfModule> Code (markup):
I don't think you can include a file like this: user.php?do=login Why not create a file for everything? In this case, create a file named "login.php" and do this: if(empty($do)) $file_name = $page; else $file_name = $do; This way, you will include the $do if it exists or the $page if it does not.
Then I would have loads of different pages, and I already have one user.php. Ill see on some other forums what they think, then I might do that, Thanks though!
If you have to do it this way, then there is still a way Include the $page only and inside the page, process the $do.