Forum Moderators: phranque

Message Too Old, No Replies

Grueling trailing slash problem

done lots of research but can't solve simple problem - help!

         

uberslacker

7:40 pm on Jan 16, 2006 (gmt 0)

10+ Year Member



Hi all. I run my site using mambo content management system. I host off a shared hosting plan. I have the trailing slash issue and can't fix it on my own. i have done tons of research (hours of research and testing) and can't fix it. When someone goes to www.mysite.com/blahblahblah/ it works however if the slash is dropped, it gets a 404 error page. As we all know yahoo drops the ending slash so a lot of my links don't work from yahoo's search. Here's is my crazy htaccess file:

Options +FollowSymLinks
RewriteEngine On

# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update YourMamboDirectory (just / for root)

RewriteBase /

#
# Rules
#
# append "/" if requested URI contains no filetype and does not end in "/"

#
RedirectMatch permanent ^/mambo$ [mysite.com...]
#
#if no www then add it
RewriteCond %{HTTP_HOST}!^www\.mysite\.com
RewriteRule (.*) [mysite.com...] [L,R=301]
#
# if requested URI does not exist as a file
RewriteCond %{REQUEST_FILENAME}!-f
# and if requested URI does not exist as a directory
RewriteCond %{REQUEST_FILENAME}!-d
# then rewrite <anything> to index.php and stop processing rules for this pass
RewriteRule ^(.*) index.php

I have tried adding things like:
#RewriteCond %{REQUEST_URI}!(\.¦/$)
#RewriteRule (.+) [mysite.com...] [R=301,L]

but it doesn't seem to work wherever I put it. Can anyone help me with this crazy issue? jdmorgan seems to know alot about this... :) ;)

jdMorgan

3:15 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



uberslacker,

Welcome to WebmasterWorld!

I looked at your code several times, but other than the misplaced comments and a possible problem with the order of the rules, I don't see much wrong. I'm wondering if you fell into a common trap here -- this forum deletes spaces and changes a few characters. I have fixed everything I saw that was "non-optimal" and restored the missing spaces. Try this code, but be sure to change the broken pipe "¦" character to a solid pipe before use:


# Redirects using mod_alias
#
RedirectMatch permanent ^/mambo$ http://www.example.com
#
# RewriteRules using mod_rewrite
#
# if no www then add it
RewriteCond %{HTTP_HOST} !^www\.mysite\.com
RewriteRule (.*) http://www.example.com/$1 [L,R=301]
#
# append "/" if requested URI contains no filetype and does not end in "/"
RewriteCond %{REQUEST_URI} !(\.¦/$)
RewriteRule (.+) http://www.example.com/$1/ [R=301,L]
#
# rewrite all requests to index.php, unless requested resource exists
# if URL not already rewritten to index.php
RewriteCond %{REQUEST_URI} !^/index\.php$
# and if requested URI does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# and if requested URI does not exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# then rewrite <anything> to index.php
RewriteRule (.*) /index.php [L]

Jim

uberslacker

11:35 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



jd - I sticky mailed you with a couple more details. I couldn't get that code to work correctly. It's drivin me nuts :)

jdMorgan

11:49 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let me ask a couple of basic questions:

Do *any* of these rules work?

Do you know for a fact that your host supports mod_rewrite in .htaccess?

Jim

uberslacker

12:00 am on Jan 18, 2006 (gmt 0)

10+ Year Member



Yes, I have all the rules working except for that one. if i go to mysite.com it instantly goes to www.mysite.com. That's what it says right in the browser url.

This line is working too:
RedirectMatch permanent ^/mambo$ [mysite.com...]

if i go to mysite.com/mambo/* it directs to the page without the mambo.

I have one other rule which I threw in that checks to see if there is a?&=ref at the end of the url and it gets rid of that. That seems to be working to. However, I can't get that ending slash thing working.

So since that other stuff is working does that mean mod-Rewrite is working? It seems like something is fishy since most of the stuff works but the trailing slash code isn't doing anything.

uberslacker

12:49 am on Jan 18, 2006 (gmt 0)

10+ Year Member



I just checked on my hosts website and it said:

"Yes, our Linux hosting accounts support most mod_rewrite functionality."

So, that should be working.

jdMorgan

1:54 am on Jan 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, if some of the RewriteRules work, then mod_rewrite must be working.

Please confirm that you read this line above and that your code has been adjusted accordingly:

Try this code, but be sure to change the broken pipe "¦" character to a solid pipe before use

Jim

uberslacker

3:04 am on Jan 18, 2006 (gmt 0)

10+ Year Member



yes, I fixed the pipe.

jdMorgan

3:45 am on Jan 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ugh.

OK, what is in your server error log when you get a 404 because of the missing trailing slash?

Jim

Key_Master

4:01 am on Jan 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe this can help?
[httpd.apache.org...]

uberslacker

12:39 pm on Jan 18, 2006 (gmt 0)

10+ Year Member



Since it's just a shared account (on a godaddy shared plan), I don't think i have access to any server files. I can just get to my ftp folder.

jd01

12:29 am on Jan 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very interesting, have you emptied your browser cache?

If you have and you still cannot get it to work, I would try to narrow down where the problem is, by removing (or commenting out) all rules except the rule for the trailing /.

Then add them back in the same order as they are in currently one set at a time. I do not see any conflict, or reason for them to not work, but if we isolate each set, we should be able to make sure it functions on its own, and then check to see how it functions with the other rulesets as well --- maybe then we can figure out where it is breaking.

Justin

Key_Master

12:36 am on Jan 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"DirectorySlash On" can be added to your .htaccess file.

You have to have Apache v2.0.51 or later though.

uberslacker

1:31 am on Jan 19, 2006 (gmt 0)

10+ Year Member



Ok. So first I tried adding the directory slash line. When i did that nothing on my site worked at all. Guess godaddy musn't be running that version of apache :)

So, then I took all the rules out except for the trailing slash rule. when I did this, none of my content items would work at all.

So I notice that all the other rules work except this one. It seems weird. But it's really bothering me.

I think i mentioned before that I have sef running in mambo (that is the feature that makes mambo write better url's for search engines). Still, i wouldn't think that would affect this one issue. doh!