Jump to content

Mod_Rewrite


Recommended Posts

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]

Link to comment
Share on other sites

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: ./");
}
?>

Link to comment
Share on other sites

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."

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

./ 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");



Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.