I have a problem that I can't find the answer to anywhere. We'll maybe I've found the answer, but didn't realise it.
I'm using Apache's <Files> and ForceType with some PHP code to create directory-style URLS for my dynamic site.
The problem is that the pages work with or without trailing slashes. The application consistently uses trailing slashes; I would like to add trailing slashes to URLs missing the trailing slash. I found some rewrite rules here that look like they should work, but don't.
The script that creates the URLs looks like this:
- Code: Select all
<A HREF=myscript/".str_replace("%20", "_", rawurlencode($var1))."/".str_replace("%20", "_", rawurlencode($var2))."/>".Anchor Text</A>
My .htaccess file looks like this:
- Code: Select all
Options +FollowSymlinks
RewriteEngine On
# If it's not a request for a real file.
RewriteCond %{SCRIPT_FILENAME} !-f
# Add the trailing slash. I removed the L flag because I want to process the next rule, <Files myscript>, but it's not actually a mod_rewrite rule so maybe I can leave it in.
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301]
<Files myscript>
ForceType x-mapp-php4
</Files>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://mydomain.com/error.php [L]
rewriteCond %{http_host} ^www.mydomain.com [nc]
rewriteRule ^(.*)$ http://mydomain.com/$1 [r=301,nc,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ http://mydomain.com/ [R=301,L]
And the script, named myscript (without extension) in the above .htaccess file, looks like this:
- Code: Select all
$data = explode("/", $HTTP_SERVER_VARS['PATH_INFO']);
$var1_name = $data[1];
$var1_name = str_replace("_", " ", $var1);
$query = "MySQL query that selects corresponding unique ID";
$select = mysql_query($query);
$var1id = mysql_result($select, 0);
$var2_name = $data[2];
$var2_name = str_replace("_", " ", $var2_name);
$query = "MySQL query that selects corresponding unique ID";
$select = mysql_query($query);
$var2id = mysql_result($select, 0);
Thanks for any help.
Damon
[/code]