homepage Welcome to WebmasterWorld Guest from 54.198.42.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
trailing slash problem
messed sth up in htaccess
muesli




msg:3058402
 8:16 am on Aug 24, 2006 (gmt 0)

hi,

mod_dir seems to work fine on my domain (i.e. folder do work also without trailing slash), however i have added the following htaccess file to my main folder "/francais/" and now i get an error 400 (bad request) when leaving out the slash ("/francais"):

RewriteEngine on

# Don't rewrite requests for files in MediaWiki subdirectories,
# MediaWiki PHP files, HTTP error documents
RewriteCond %{REQUEST_URI}!^/francais/(stylesheetsmageskins)
RewriteCond %{REQUEST_URI}!^/francais/(redirectexvcndex).php
RewriteCond %{REQUEST_URI}!^/francais/error/(40(1񔬊)500).html
RewriteCond %{REQUEST_URI}!^/francais/nowiki
# include these last two lines if you use the analog stats
RewriteCond %{REQUEST_URI}!^/francais/failed_auth.html$

RewriteRule ^(.*)$ index.php?title=$1 [QSA]

i'm an apache newbee.. what did i do wrong? (have searched before i posted, didn't find any answer that i could fully understand.)

thanks in advance, muesli

 

jdMorgan




msg:3059402
 9:51 pm on Aug 24, 2006 (gmt 0)

A possible cause is an infinite loop. There is nothing in the original code to stop a request for index.php from being rewritten to index.php forever. Adding another RewriteCond will prevent this:

# Prevent 'infinite' loop
RewriteCond %{REQUEST_URI} !index\.php
# Don't rewrite requests for files in MediaWiki subdirectories,
# MediaWiki PHP files, HTTP error documents
RewriteCond %{REQUEST_URI} !^/francais/(stylesheetsmageskins)
RewriteCond %{REQUEST_URI} !^/francais/(redirectexvcndex)\.php
RewriteCond %{REQUEST_URI} !^/francais/error/(40(1񔬊)500)\.html
RewriteCond %{REQUEST_URI} !^/francais/nowiki
# include these last two lines if you use the analog stats
RewriteCond %{REQUEST_URI} !^/francais/failed_auth\.html$
RewriteRule (.*) index.php?title=$1 [QSA,L]

Note several other minor corrections/adjustments.

Note also that you could combine several of the RewriteCond lines if you wanted to.

Jim

muesli




msg:3061107
 6:47 am on Aug 26, 2006 (gmt 0)

JD, thanks for that suggestion! i tried it and leaving out the trailing slash works now. but: the rewritten urls now give error 404s.

i.e.: /francais/index.php?title=Pagename works and is being rewritten to /francais/Pagename, which gives a page not found.

Caterham




msg:3062544
 1:21 am on Aug 28, 2006 (gmt 0)

And you did not forget to copy the line RewriteEngine on?

jdMorgan




msg:3062636
 3:53 am on Aug 28, 2006 (gmt 0)

Good point.

For those just joining the fray, your mod_rewrite code in .htaccess must be preceded by

RewriteEngine on

And that in turn may also need to be preceded by

Options +FollowSymLinks

unless your host has already configured this option in your server setup. FollowSymLinks or SymLinksIfOwnerMatch must be configured in either the server config or in your .htaccess file(s) in order to enable mod_rewrite.

Futhermore, although it's odd that they do this, many hosts turn on MultiViews by default, and this can interfere with all sorts of rewrites in many different ways. So if you do not use MultiViews (content negotiation) then you may want to try

Options +FollowSymLinks -MultiViews

followed by

RewriteEngine on

before your mod_rewrite rules.

Jim

muesli




msg:3064106
 9:04 am on Aug 29, 2006 (gmt 0)

of course i had forgotten the rewrite-on line, sorry for that!

now i've tried it again with and had the following problems:

  • calling the folder w/o trailing slash still gives an error 400 (bad request)
  • stylesheets have stopped working

    the rest (rewrite) works.

    the entire code i used:


    RewriteEngine on
    # Prevent 'infinite' loop
    RewriteCond %{REQUEST_URI}!index\.php
    # Don't rewrite requests for files in MediaWiki subdirectories,
    # MediaWiki PHP files, HTTP error documents
    RewriteCond %{REQUEST_URI}!^/francais/(stylesheetsmageskins)
    RewriteCond %{REQUEST_URI}!^/francais/(redirectexvcndex)\.php
    RewriteCond %{REQUEST_URI}!^/francais/error/(40(1񔬊)500)\.html
    RewriteCond %{REQUEST_URI}!^/francais/nowiki
    # include these last two lines if you use the analog stats
    RewriteCond %{REQUEST_URI}!^/francais/failed_auth\.html$
    RewriteRule (.*) index.php?title=$1 [QSA,L]

  • Caterham




    msg:3064291
     1:03 pm on Aug 29, 2006 (gmt 0)

    You're not using the most recent version of the 2.2 branch? Because there is a bug in the previous branches while mod_rewrite acts before mod_dir can send the trailing slash.
    Try to move with all your rules to /.htaccess instead of /francais/.htaccess

    RewriteEngine on
    # Prevent 'infinite' loop
    RewriteCond %{REQUEST_URI} !=/francais/index.php
    # Don't rewrite requests for files in MediaWiki subdirectories,
    # MediaWiki PHP files, HTTP error documents
    RewriteCond %{REQUEST_URI} !^/francais/(stylesheetsmageskins)
    RewriteCond %{REQUEST_URI} !^/francais/(redirectexvcndex)\.php$
    RewriteCond %{REQUEST_URI} !^/francais/error/(40(1񔬊)500)\.html$
    RewriteCond %{REQUEST_URI} !^/francais/nowiki
    # include these last two lines if you use the analog stats
    RewriteCond %{REQUEST_URI} !=/francais/failed_auth.html
    RewriteRule ^francais/(.*) /francais/index.php?title=$1 [QSA,L]

    muesli




    msg:3065517
     10:04 am on Aug 30, 2006 (gmt 0)

    the suggestion to move everything into the root folder is a good one, i tried before but failed.

    i tried your code and it worked like a charm! as i've got a redirect in place there and two identical main folders (english & french) i tried to merge the rules. that, however, broke everything again (server errors). what did i do wrong now?


    Redirect permanent /index.html http://www.example.com/english/
    RewriteEngine on
    # Prevent 'infinite' loop
    RewriteCond %{REQUEST_URI}!=/francais/index.php
    RewriteCond %{REQUEST_URI}!=/english/index.php
    # Don't rewrite requests for files in MediaWiki subdirectories,
    # MediaWiki PHP files, HTTP error documents
    RewriteCond %{REQUEST_URI}!^/francais/(stylesheetsmageskins)
    RewriteCond %{REQUEST_URI}!^/francais/(redirectexvcndex)\.php$
    RewriteCond %{REQUEST_URI}!^/francais/error/(40(1񔬊)500)\.html$
    RewriteCond %{REQUEST_URI}!^/francais/nowiki
    RewriteCond %{REQUEST_URI}!^/english/(stylesheetsmageskins)
    RewriteCond %{REQUEST_URI}!^/english/(redirectexvcndex)\.php$
    RewriteCond %{REQUEST_URI}!^/english/error/(40(1񔬊)500)\.html$
    RewriteCond %{REQUEST_URI}!^/english/nowiki
    # include these last two lines if you use the analog stats
    RewriteCond %{REQUEST_URI}!=/francais/failed_auth.html
    RewriteRule ^francais/(.*) /francais/index.php?title=$1 [QSA,L]
    RewriteCond %{REQUEST_URI}!=/english/failed_auth.html
    RewriteRule ^english/(.*) /english/index.php?title=$1 [QSA,L]

    Caterham




    msg:3065674
     12:11 pm on Aug 30, 2006 (gmt 0)

    Due to the procssing rule-pattern --> condition(s) --> subst., a condition will be ckecked only for that corresponding rule.

    But you can use one single rule here (while we need now in some cases a RegEx again instead of the lex. equal operator).

    I won't recommend mixing up mod_alias (redirect dirctive) with mod_rewrite, it creates no problem here but in other cases.

    RewriteEngine on
    RewriteRule ^index\.html$ http://www.example.com/english/ [R=301,L]
    RewriteCond %{REQUEST_URI} !^/(francais¦english)/index\.php$
    RewriteCond %{REQUEST_URI} !^/(francais¦english)/(stylesheets¦images¦skins¦nowiki)
    RewriteCond %{REQUEST_URI} !^/(francais¦english)/(redirectexvcndex)\.php$
    RewriteCond %{REQUEST_URI} !^/(francais¦english)/error/(40(1񔬊)500)\.html$
    RewriteCond %{REQUEST_URI} !^/(francais¦english)/failed_auth\.html$
    RewriteRule ^(francais¦english)/(.*) /$1/index.php?title=$2 [QSA,L]

    muesli




    msg:3067143
     10:12 am on Aug 31, 2006 (gmt 0)

    caterham, thanks for that!

    i tried it out and it unfortunately didn't quite work:

  • www.example.com didn't redirect to /english/, showed folder index instead
  • /english/ showed a 404

    what i did:

  • placed the exact copy of your suggestion in the root, with my domain instead of example.com of course
  • emptied the two subfolder-htaccess' by commenting everything out

    what puzzles me is that not even the simple redirect worked, although it looks perfect:

    RewriteRule ^index\.html$ http://www.example.com/english/ [R=301,L]

  • muesli




    msg:3067177
     10:55 am on Aug 31, 2006 (gmt 0)

    i think i have identified one error, within last line a $-sign is missing, it should maybe read:

    RewriteRule ^(francaisnglish)/(.*)$ /$1/index.php?title=$2 [QSA,L]

    however, i tested and it didn't change anything.

    Caterham




    msg:3067867
     7:41 pm on Aug 31, 2006 (gmt 0)

    www.example.com
    Depending upon your apache branch and DirectoryIndex and existing index-files, the first rule won't catch a "root" request (example.com/) but only /index.html. so you might try to use

    RewriteRule ^($ndex\.html$) http://www.example.com/english/ [R=301,L]

    instead.
    # /english/ showed a 404
    Try to add the R flag to the last rule to see if the substitution is applied.

    The pipe character must be replaced with solid ones from your keyboard because the forum software modifies them.

    [edited by: Caterham at 7:42 pm (utc) on Aug. 31, 2006]

    muesli




    msg:3068088
     10:03 pm on Aug 31, 2006 (gmt 0)

    thank you VERY much for your help, now everything works fine. the pipe-issue had escaped my attention, that solved everything, along with the modified redirect. setting the [R] flag wasn't necessary.

    .htaccess is still voodoo to me, although this thread has tought me some basics.

    thanks again!

    Global Options:
     top home search open messages active posts  
     

    Home / Forums Index / Code, Content, and Presentation / Apache Web Server
    rss feed

    All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
    Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
    WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
    © Webmaster World 1996-2014 all rights reserved