HDFilmMaker2112 Posted June 19, 2012 Share Posted June 19, 2012 I know this isn't the right sub-forum, but this is urgent the Apache sub-forum hardly gets any views. This rewrite is cause all of my css and javascript files not to load. Even my home page http://www.kynxin.com/ doesn't load it's style sheets. Options -MultiViews RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC] RewriteRule . index.php [L] [OR] RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/?$ index.php?p=$1 [QSA,L,NC] [OR] RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/([A-Za-z0-9_]+)/?$ index.php?p=$1&s=$2 [QSA,L,NC] Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/ Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 Also, now after trying the above rewrite code, my logout page won't log me out. Worked fine prior. <?php session_start(); /*Unset and destroy users session data*/ if(isset($_SESSION['username'])){ unset($_SESSION['username']); unset($_SESSION['password']); unset($_SESSION['user_id']); unset($_SESSION['homepage']); session_destroy(); header("location: ./"); } else{ header("location: ./"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355061 Share on other sites More sharing options...
requinix Posted June 19, 2012 Share Posted June 19, 2012 1. RewriteConds only apply to the next RewriteRule. And only the one. 2. Not only can you not [OR] a RewriteRule, it wouldn't even make sense to. I know this isn't the right sub-forum, but this is urgent the Apache sub-forum hardly gets any views. "Oh sorry officer, I know I'm going the wrong way down a one-way street, but I'm late for work and I'm too important." Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355064 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 Alright, got the rewrite issue fixed. logout.php is still not logging out. As a matter of fact no .php files are loading correctly. Options -MultiViews RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC] RewriteRule . index.php [L] RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC] RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/?$ index.php?p=$1 [QSA,L,NC] RewriteCond %{REQUEST_URI} !((.*).(js|css))$ [NC] RewriteRule ^([A-Za-z0-9#_\.\$\)\(\*\^]+)/([A-Za-z0-9_]+)/?$ index.php?p=$1&s=$2 [QSA,L,NC] Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355066 Share on other sites More sharing options...
requinix Posted June 19, 2012 Share Posted June 19, 2012 ./ is relative to what the browser thinks is the current directory. When your friendly URLs have slashes then that might not match up with what you consider to be the current directory. Long story short use absolute locations everywhere. header("Location: /path/to/here"); Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355073 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 And when it changes (and it will, I'm on a development server with a different root then what the production site will be on), then I have to go back and change 100s of urls? Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355080 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 And that's also not working for my login form. I can't use an absolute path in my forms HTML (because it just stacks on top of my domain name); and if I use /login.php, when I submit the form it just reloads the page that I was just on, and shows /login.php in the address bar. See for yourself: http://www.kynxin.com/ click the login button. It'll just reload the same page and add /login.php into the address bar. Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355085 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 It's because of this: RewriteRule . index.php [L] But I need that for my homepage to show. Otherwise I always get another page: /*This always executes because the other rewrite always generates a p= . For some reason it executes even when the requested page is the domain name with no additional information in the address bar. So http://www.kynxin.com/ loads a blank profile page*/ elseif(isset($_GET['p']) && $_GET['p']!=null && $_GET['p']!=""){ $url=$_GET['p']; $content.=' <div class="left profile_left_width"> <div class="profile_photo_details_wrapper"> <div class="profile_photo"> Profile Photo </div> <div class="profile_details"> Profile Details </div> </div> <div class="profile_activity"> </div> </div> <div class="right profile_right_width"> <div class="profile_cover"> Cover Photo </div> <div class="profile_mystream"> Status Updates </div> </div> '; } /*Default page - Front Page*/ else{ //Front page code } Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355091 Share on other sites More sharing options...
requinix Posted June 19, 2012 Share Posted June 19, 2012 Then let's try just a new set of rules. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/([^/]+))?/?$ index.php?p=$1&s=$3 [L,QSA] Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355250 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 Then let's try just a new set of rules. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)(/([^/]+))?/?$ index.php?p=$1&s=$3 [L,QSA] That does work, but now I'm running into a problem with my login script. If you click the log-in button with not details entered, it changes the top menu links to as if you were logged in; it also redirects back to the log-in form with the error message saying wrong username or password, which it should. Then if you click on anyone of the links in the top menu, it changes it back to the not logged in menu: <?php session_start(); $viewed_homepage=$_SESSION['homepage']; $login_username=$_POST['email']; $login_username=strtolower($login_username); $login_password=$_POST['password']; $login_stay_logged_in=$_POST['stayloggedin']; $login_form_submitted=$_POST['login_form_submit']; /*if form has been submitted and the front page has been viewed*/ if($viewed_homepage=="viewed" && $login_form_submitted=="submitted"){ require_once 'db_select.php'; require_once 'function.php'; /*Connect to DB*/ $LoginDB = $db->connect('mysqli', 'persist', 'db418598519'); /*Encode - Sanitize user input for query*/ $sanitized_email = $LoginDB->mysqli_sanitize($login_username); $encoded_password = $LoginDB->kam3($login_password); /*run query*/ $result = $LoginDB->query("SELECT * FROM user WHERE email_address='$sanitized_email' AND password='$encoded_password'"); $num_rows = $result->num_rows; $rows = $result->fetch_assoc(); /*Close Database Connection*/ $LoginDB->close(); /*If user matches a database entry log-in*/ if(($num_rows==1) && ($rows["email_address"]==$sanitized_email && $rows["password"]==$encoded_password)){ /*Set Session/Cookie data to stay logged in*/ $_SESSION['username']=$sanitized_email; $_SESSION['password']=$encoded_password; $_SESSION['user_id']=$rows['id']; /*If selected, Set Cookies*/ if($login_stay_logged_in=="yes"){ /*Connect to DB to insert cookie key*/ $CookieDB = $db->connect('mysqli', 'persist', 'db418598519'); /*Generate key, encode username, and get current time for cookies */ $hased_value = kam3(md5(generatepassword(6))); $hashed_username = md5s($rows["email_address"]); $time = time(); setcookie("knxn_hash", $hased_value, time()+(86400*180), "/", "beta.area51entertainment.com",false,false); setcookie("knxn_username", $hased_username, time()+(86400*180), "/", "beta.area51entertainment.com",false,false); setcookie("knxn_visited", $time, time()+(86400*180), "/", "beta.area51entertainment.com",false,false); } /*Unset error alert for log-in form*/ unset($_SESSION['login_error']); /*redirect to dashboard*/ header("Location: /home"); } else{ /*redirect to index.php with error message*/ $_SESSION['login_error']="error"; header("Location: /"); } } else{ /*redirect to index.php if submission didn't originate from log-in form on index.php*/ header("Location: /"); } ?> The top menu changes just based on whether or not the variable $_SESSION['username'] is set or not. Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355279 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 Also, to add to my last post. When I log-in with valid credentials it goes to the right page, but when I click on any of the links in the links bar, it logs me out. Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355291 Share on other sites More sharing options...
HDFilmMaker2112 Posted June 19, 2012 Author Share Posted June 19, 2012 I'm really ready to just abandon this whole mod_rewrite thing. Everything worked fine until I tried to rewrite URLs. Quote Link to comment https://forums.phpfreaks.com/topic/264418-mod_rewrite/#findComment-1355294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.