Welcome to WebmasterWorld Guest from 50.19.34.234

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod_rewrite add too much

it adds /var/www where it schould not be

     

Jeena Paradies

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

10+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

10+ Year Member



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

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

10+ Year Member



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

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

10+ Year Member



And whot should I do to avoid it?

Jeena Paradies

jdMorgan

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month