homepage Welcome to WebmasterWorld Guest from 184.73.52.98
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod_rewrite add too much
it adds /var/www where it schould not be
Jeena Paradies




msg:1516337
 10:40 pm on Apr 5, 2004 (gmt 0)

Hello, I'm Jeena Paradies from Germany.

I want to add trailing slashes to my url with mod_rewrite. I found a rule for that and placed it at [localhost...]

RewriteEngine on
RewriteRule ^([a-zA-Z0-9\-_]+)$ $1/ [R]

I want to rewrite:

[localhost...]
to
[localhost...]

But there ist a problem, mod_rewrite rewrites ist to

[localhost...]

and produce a 404. How can I avoid this behavior an get [localhost...] ?

Jeena Paradies

 

jdMorgan




msg:1516338
 11:31 pm on Apr 5, 2004 (gmt 0)

Jeena,

Welcome to WebmasterWorld [webmasterworld.com]!

I would suggest:

RewriteEngine on
# If the URL does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# and the URL does not contain a full stop (Example: inde[b]x.h[/b]tml)
RewriteCond %{REQUEST_URI} !\.
# rewrite it so that it ends with a slash
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Replace "Example.com" with your actual domain (or with "localhost" for testing).

The substitution URL should always contain "http://www.<domain>/" when the [R} flag is used.

Jim

Jeena Paradies




msg:1516339
 6:21 am on Apr 6, 2004 (gmt 0)

I think your code can not work where is the slash?

But you had very good Ideas and I have rewriten a little bit:

RewriteEngine on
# If the URL does not end with a slash
RewriteCond %{REQUEST_URI}!/$
# and the URL does not contain a full stop (Example: index.html)
RewriteCond %{REQUEST_URI}!\.
# and the URL is not a directory
RewriteCond %{REQUEST_URI}!-d
# rewrite it so that it ends with a slash
RewriteRule (.*) http://localhost/open/Webs/jeenas-home5/artikel/$1/ [R=301,L]

It works fine now except that if I write:

http://localhost/open/Webs/jeenas-home5/artikel

I get:

http://localhost/open/Webs/jeenas-home5/artikel//var/www/open/Webs/jeenas-home5/artikel/

how can I avoid that?

WibbleWobble




msg:1516340
 11:41 am on Apr 6, 2004 (gmt 0)

Thats because [correct me if I'm wrong] your last rule (beginning RewriteRule (.*)) is matching (.*) and inserting it into the /$1/ namespace [its putting var/www/open/etc[/b] into the space after artikel/]

Jeena Paradies




msg:1516341
 11:44 am on Apr 6, 2004 (gmt 0)

And whot should I do to avoid it?

Jeena Paradies

jdMorgan




msg:1516342
 1:12 am on Apr 7, 2004 (gmt 0)

Jeena,

This sounds like you have a configuration problem or possibly another rewrite (maybe at a higher level) that is interfering with your rewrite by adding the /var/www path. Have you looked at the RewriteBase directive?

Jim

Jeena Paradies




msg:1516343
 9:48 pm on Apr 7, 2004 (gmt 0)

IT WORKS! After two weeks with 4-5 hours Work on this problem it works!

Big thanks to you guys and especially to you jdMorgan!

RewriteEngine on
#RewriteBase /artikel
# If the URL does not end with a slash
RewriteCond %{REQUEST_URI}!/$
# and the URL does not contain a full stop (Example: index.html)
RewriteCond %{REQUEST_URI}!\.
# not artikel
RewriteCond %{REQUEST_URI}!artikel$
# rewrite it so that it ends with a slash
RewriteRule (.*) [localhost...] [R=301,L]

RewriteRule "^([a-zA-Z0-9\-_]+)/" ./artikel.php?artikel=$1

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved