Forum Moderators: phranque
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¦images¦skins)
RewriteCond %{REQUEST_URI}!^/francais/(redirect¦texvc¦index).php
RewriteCond %{REQUEST_URI}!^/francais/error/(40(1¦3¦4)¦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
# 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¦images¦skins)
RewriteCond %{REQUEST_URI} !^/francais/(redirect¦texvc¦index)\.php
RewriteCond %{REQUEST_URI} !^/francais/error/(40(1¦3¦4)¦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 also that you could combine several of the RewriteCond lines if you wanted to.
Jim
For those just joining the fray, your mod_rewrite code in .htaccess must be preceded by
RewriteEngine on
Options +FollowSymLinks
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
RewriteEngine on
Jim
now i've tried it again with and had the following problems:
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¦images¦skins)
RewriteCond %{REQUEST_URI}!^/francais/(redirect¦texvc¦index)\.php
RewriteCond %{REQUEST_URI}!^/francais/error/(40(1¦3¦4)¦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]
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¦images¦skins)
RewriteCond %{REQUEST_URI} !^/francais/(redirect¦texvc¦index)\.php$
RewriteCond %{REQUEST_URI} !^/francais/error/(40(1¦3¦4)¦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]
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¦images¦skins)
RewriteCond %{REQUEST_URI}!^/francais/(redirect¦texvc¦index)\.php$
RewriteCond %{REQUEST_URI}!^/francais/error/(40(1¦3¦4)¦500)\.html$
RewriteCond %{REQUEST_URI}!^/francais/nowiki
RewriteCond %{REQUEST_URI}!^/english/(stylesheets¦images¦skins)
RewriteCond %{REQUEST_URI}!^/english/(redirect¦texvc¦index)\.php$
RewriteCond %{REQUEST_URI}!^/english/error/(40(1¦3¦4)¦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]
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¦texvc¦index)\.php$
RewriteCond %{REQUEST_URI} !^/(francais¦english)/error/(40(1¦3¦4)¦500)\.html$
RewriteCond %{REQUEST_URI} !^/(francais¦english)/failed_auth\.html$
RewriteRule ^(francais¦english)/(.*) /$1/index.php?title=$2 [QSA,L]
i tried it out and it unfortunately didn't quite work:
what i did:
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]
www.example.comDepending 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 ^($¦index\.html$) http://www.example.com/english/ [R=301,L] instead.
# /english/ showed a 404Try 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]