Forum Moderators: phranque

Message Too Old, No Replies

Trailing slash in mod rewrite

Howto?

         

Ruben

4:16 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



I have the following in my htaccess:

RewriteRule ^([^/]+)/$ index.php?dir=$1 [L]
RewriteRule ^([^/]+)/(.+)\.html$ index.php?dir=$1&file=$2 [L]

This works very good for:

[subdomain.domain.nl...]

and

[subdomain.domain.nl...]

, it doesn't work for

[subdomain.domain.nl...]

I want,

[subdomain.domain.nl...]

be redirected to:

[subdomain.domain.nl...]

Is that possible?

RedAndy

10:27 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Hi,

Am I right in thinking that /dir/ doesn't 'physicaly' exist and is only in your database?

If so then you probably have a way of telling that it is a 'directory' - a boolean flag or something? Using that you can redirect it within your scripting language and restart the process - eg in php something like


if ($is_directory) {
$new_url="http://servername/".$full_url."/");
header("HTTP/1.0 301 Moved Permanently");
header("Location: http://".$new_url);
die(); //or not...
}

Otherwise you're trying to detect something in a database from somewhere that can't see your data,

hth,

Andy

Ruben

10:57 am on Mar 17, 2006 (gmt 0)

10+ Year Member



Well in php it can be done like the way you say, but I want to have it in htaccess.. i also tried something with the? after the / but it won't help me!

jdMorgan

7:44 pm on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# If no trailing slash
RewriteCond $1 !/$
# but exists as a directory when slash is added
RewriteCond %{REQUEST_FILENAME}/ -d
# Then add a trailing slash and redirect
RewriteRule (.+) http://www.example.com/$1/ [R=301,L]

Jim