Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite help - forward/case sensitivity questions

A newbie needs help htaccess mod_rewrite

         

kambei

6:37 am on Jan 21, 2008 (gmt 0)

10+ Year Member



I run a small site for a friend and he is running a few promotions right now where he is sending out urls such as http://example.com/FSBO or http://example.com/equityclub and so the index.html files are being access from within these folders.

I discovered the case sensitivity problem straight away, and I've been looking for a clear solution to either have any emails sent to the above addresses sent to the right folder, regardless of case, or using mod_spelling, but I can't get anything to work.

This is what I have tried:


CheckSpelling On
RewriteEngine On
RewriteRule ^fsbo/index\.html ^FSBO/index.html [NC]

What am I doing wrong? I would really appreciate any help.

Thanks, Matt

[edited by: jdMorgan at 1:43 pm (utc) on Jan. 21, 2008]
[edit reason] example.com [/edit]

jdMorgan

1:46 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your RewriteRule contains syntax errors.

Also, consider whether you want to use an internal rewrite, or an external 301-Moved Permanently redirect; Using an internal rewrite leaves all case variations of these URLs to be index by search engines, creating a duplicate-content problem which may impair their search ranking.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

gergoe

2:09 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



CheckSpelling already should take care of your problem, you don't need mod_rewrite then (so the last two lines should go).

If that does not solve your problem, you can indeed use mod_rewrite (and remove CheckSpelling On), but rewriting "something" to the "same something" makes no sense, this can cause an infinite loop.
Then; if you have a directory called FSBO, and you type fsbo in the address bar of he browser (but not the index.html), then Apache will not find that resource, because your RewriteRule rewrites only request for FSBO/index.html, but since Apache does not find the directory, it will never reach your RewriteRule.
Also note that in the replacement string of RewriteRule, you don't need to use regular expressions anymore, so the starting anchor (^) is not needed anymore, if you leave it there, it will become the part of the rewritten url.

To make your mod_rewrite directives effective, you'll need something like this:

# 
# This is needed to make the internal rewriting possible
# in .htaccess files
Options +FollowSymLinks
RewriteEngine On
#
# Tell mod_rewrite that we're in the root directory
# (probably would work without this too - depends on the server config)
RewriteBase /
#
# If the requested resource is the anything from the /FSBO
# directory (with all capitals), do not process the next RewriteRule.
# Note the exclamation mark.
RewriteCond %{REQUEST_URI}
!^/FSBO(/.*)?$ 
#
# Rewrite anything from the fsbo directory regardless of its case
# to the FSBO directory, but only if the above RewriteCond did not match.
RewriteRule ^fsbo(/(.*))?$ /FSBO/$2 [NC,L]

kambei

2:16 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



Thanks Gergoe,

That is so so much help, I've been well confused.

kambei

6:56 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



This is working ok, but my styles are no longer working.. Any insight?

gergoe

8:30 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



Remember that it is the client (browser or robot) that resolves relative links. It does so by using the lowest-level directory path present in the page URL currently showing in its address bar. Therefore, the behaviour you see is expected.

There are several choices to avoid problems with link resolution:

  • Use server-relative links, instead of page-relative links -- e.g. <img scr="/logo.gif>
  • Use canonical links: <img src="http://example.com/logo.gif">
  • Rewrite requests for included objects back to the correct path (rewrite page-included objects only, not the pages themselves)

    Jim

  • See [webmasterworld.com...]