Free Ringtone - Cheap Jordans - Samsung - Loans - Nationwide Building Society

PDA

View Full Version : Modrewrite and trailing slashes


ozgression
Apr 18th 2006, 12:46 am
Ok, so I have the following in my htaccess:

Options +FollowSymLinksRewriteEngine onRewriteRule ^(.*)/?$ index.php?page=$1 [QSA,L]


Now, that works great for site.com/page , but doesnt work for site.com/page/ <-- note the trailing slash.

What I want to do is have a trailing slash and if you type the url without the trailing slash you are forced to the trailing slash version (make sense?).

This sort of stuff makes no sense to me and I assume (hope) that this something simple that a good coder knows how to fix, simply. :)

Any help is appreciated.

exam
Apr 18th 2006, 12:50 am
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*[^/])$ $1/ [R=301]
RewriteRule ^(.*)/$ index.php?page=$1 [QSA,L]

ozgression
Apr 18th 2006, 6:36 am
Hi exam,

I tried that code, but it didnt work. Thanks anyway, though. :)

exam
Apr 18th 2006, 10:10 am
Let's see, you might have to escape the slashOptions +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*[^\/])$ $1/ [R=301]
RewriteRule ^(.*)\/$ index.php?page=$1 [QSA,L] What error did it give you?

ozgression
Apr 18th 2006, 3:33 pm
Hi, still didn't work. I am getting this error:

Moved Permanently
The document has moved here.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

... if I use trailing slashes or not.

exam
Apr 18th 2006, 4:07 pm
Hi, still didn't work. I am getting this error:

Moved Permanently
The document has moved here.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

... if I use trailing slashes or not.
1. What browser are you using to view your site in?
2. Do you have anything else in your .htaccess file? If so, can you post it here?

ozgression
Apr 18th 2006, 11:03 pm
Hi... there is nothing else in my htaccess.

Here is the index.php file, though. If you know of a better way of doing all this, by all means, feel free to let me know. :)

<?php
require('/home/mysite/config.php');

if($_GET['page']) {
$page = $_GET['page'];
$q = mysql_query("SELECT * FROM cms WHERE name = '$page'");
if(mysql_num_rows($q)) {
// insert the correct page
$page_info = mysql_fetch_array($q);
} else {
// the requested page is not in the db, default to home
$page_info = mysql_fetch_array(mysql_query("SELECT * FROM cms WHERE name = 'home'"));
$page = 'home';
}
} else {
// there's no query string, default to home
$page_info = mysql_fetch_array(mysql_query("SELECT * FROM cms WHERE name = 'home'"));
$page = 'home';
}
?>
<html>
<head>
<title><?=$page_info['title']?></title>
<meta name="keywords" content="<?=$page_info['meta_kwds']?>" />
<meta name="description" content="<?=$page_info['meta_desc']?>" />
</head>
<body>
<?php
include($page . '.inc');
?>
</body>
</html>

Nintendo
Apr 19th 2006, 12:58 am
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^.]+)$ index.php?page=$1 [QSA,L]


You can add

RewriteRule ^([^.]+)/$ index.php?page=$1 [QSA,L]

before the one RewriteRule if you need to.

ozgression
Apr 19th 2006, 5:58 pm
I'll give that a try... thanks.

ozgression
Apr 20th 2006, 2:42 am
Hehehe... it works! Thanks.

exam
Apr 22nd 2006, 5:11 pm
The Wacko mod-rewrite master has come thru again.