Easy Mod Rewrite rule (thats hard for me :) )

I am having a terrible time with this. Figured I would let you nice people have a try at it. :rofl:

All I want to do is redirect (invisibly):

any of these:

http://somedomain.com/SiteDocs/
http://somedomain.com/SiteDocs

to –>

http://somedomain.com/SiteDocs.php

This is not working for me to do even the third one:
RewriteRule ^SiteDocs/(.+)$ /SiteDocs.php

You did start the RewriteEngine didn’t you?

Make sure you did that, and then we can talk about that rule :slight_smile:

Of course :slight_smile: I have other rules that work just fine but not pertinent to this topic as I can Add or subtract those rules and this still don’t work.

I have searched and searched on this site and I still am unable to find an article that can help me with my issue. Any help will be extremely appreciated.

Thanks in advance!

Two questions:

  1. Are you on apache 1.x or 2.x ?
  2. Do also want files in those locations (if there are any?) redirected to SiteDocs.php?

Here is where I am at right now:

RewriteEngine on
RewriteRule ^([0-9]+)/(.+)$ /Default.php?ID=$1
RewriteRule ^documents$ SiteDocs/
RewriteRule ^Documents$ SiteDocs/
RewriteRule ^Documents/$ SiteDocs/
RewriteRule ^documents/$ SiteDocs/
RewriteRule ^sitedocs$ SiteDocs/
RewriteRule ^sitedocs/$ SiteDocs/
RewriteRule ^SiteDocs$ SiteDocs/
RewriteRule ^SiteDocs/$ /SiteDocs.php?$1

Rule #1 makes pretty links work Example: http://domain.com/46/Contact/Us/ - > http://domain.com/Default.php?ID=46

I can type in any of the urls but the ones with the trailing slashes will not work

so http://domain.com/documents works but http://domain.com/documents/ will not.

SiteDocs.php is definitely there and pulling up correctly.

The problem is I have multiple sites, and they each have different versions of apache or could potentiality at least. On one server, these rules work perfectly. On another the trailing slashes will not redirect.

Thank you for your help thus far.

My apologies, i did not answer your second question.

This is a pseudo directory. This directory does not exist, it is simply for ease of use purposes only.

It is easier to tell my users to go to domain.com/documents then telling them to go to domain.com/SiteDocs.php same with domains.com/SiteDocs but I got to make sure that I am catching all the variations.

Try this:


RewriteRule ^/?([Dd]ocuments|[Ss]ite[Dd]ocs)/?$ SiteDocs.php

as a replacement for:


RewriteRule ^documents$ SiteDocs/
RewriteRule ^Documents$ SiteDocs/
RewriteRule ^Documents/$ SiteDocs/
RewriteRule ^documents/$ SiteDocs/
RewriteRule ^sitedocs$ SiteDocs/
RewriteRule ^sitedocs/$ SiteDocs/
RewriteRule ^SiteDocs$ SiteDocs/
RewriteRule ^SiteDocs/$ /SiteDocs.php?$1

:slight_smile:

That does not work for the server running Apache 1.3.34 I have not tried it on any of the others yet.

It doesn’t work for any of the variations of the link. I am guessing it has something to do with that trailing slash in the rule

Oh, hold on, sounds like MultiViews is enabled and that’s causing the problems.

Put this in your .htaccess:


Options -MultiViews

MB,

If it doesn’t work for Apache 1.x, then prepend RewriteEngine on. ScallioXTX’s code is correct and he’s allowed you to have alternate capitalization on the D|d in SiteDocs, too!

Multiviews is a MAJOR PITA and should be done away with, IMHO.

Regards,

DK

Sadly, no:

this is how it stands right now, and still will not work :frowning:

RewriteEngine on
Options -MultiViews
RewriteRule ^([0-9]+)/(.+)$ /Default.php?ID=$1
RewriteRule ^/?([Dd]ocuments|[Ss]ite[Dd]ocs)/?$ SiteDocs.php

Thank you for your help thus far, it is greatly appreciated.

It shouldn’t make any difference, but my web host for this particular customer’s site is 1and1.

With my rewrites it works as long as I do not use the trailing slash.

for example:
http://domain.com/documents & http://domain.com/Documents work but not http://domain.com/documents/ & http://domain.com/Documents/

With ScallioXTX’s none of them work. But I agree his solution is both efficient and elegant.

MB,

Apache 1.x REQUIRES a leading / after the start anchor so yor first RewriteRule needs a / and the /? makes it optional (so it’ll still work with Apache 2.x).

# core directives first - technique
Options -MultiViews

RewriteEngine on
RewriteRule ^[COLOR="Red"]/?[/COLOR]([0-9]+)/(.+)$ /Default.php?ID=$1
RewriteRule ^/?([Dd]ocuments|[Ss]ite[Dd]ocs)/?$ SiteDocs.php

As for 1&1, the last thing I knew was that they didn’t allow mod_rewrite so I’m pleasantly surprised that they are allowing it (along with .htaccess). I assume that you DO have it working with other code, don’t you?

The difference with the trailing / is with the “support files,” i.e., relative links will shift directory level for every trailing / you include. Remember, Apache received a request to a specific directory level within your DocumentRoot. If your redirections change that level, your relative links will still be to the level specified by the request UNLESS you use absolute links or the HTML <base> tag (see signature tutorial for format). In other words, the redirection works but the css, js, images, etc will all be missing if you don’t handle this correctly (within the SiteDocs.php script)

Regards,

DK

Here is what I have now, and it works:


RewriteEngine on
RewriteRule ^([0-9]+)/(.+)$ /Default.php?ID=$1
RewriteRule ^documents$ SiteDocs/
RewriteRule ^Documents$ SiteDocs/
RewriteRule ^Documents/$ SiteDocs/
RewriteRule ^documents/$ SiteDocs/
RewriteRule ^sitedocs$ SiteDocs/
RewriteRule ^sitedocs/$ SiteDocs/
RewriteRule ^SiteDocs$ SiteDocs/
RewriteRule ^SiteDocs/$ /SiteDocs.php?$1

The solution XDX gave me doesn’t work at all on 1and1 (not that I am not thankful or anything as I most certainty am). 1and1 allows for me to upload the .htaccess file, and I am using it just fine, except of course it will not allow me to do many things. I have tried your code on some other servers and it works fine. So I guess the issue lies with 1and1

This is the only code that I have that performs this function. I guess I will just have to make due with what is allowed to be done on 1and1 and not worry about the rest. I just really wanted to be able to put that trailing slash on there, Which I cannot on 1and1 :frowning: