You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Scott Taylor <sc...@bigfoot.com> on 2004/01/17 09:27:08 UTC

[users@httpd] mod_rewrite simple questions

Two simple mod_rewrite questions:


1.  I would like to refer to all of my pages without the ending and with 
a trailing slash.  for instance, instead of domain.com/somepage.html it 
should be domain.com/somepage/

There may be a variety of different file types in a directory, so it 
would need a RewriteCond statement to find if there was a coresponding 
file type...

I was trying to do this with something like this

# if the page /somepage/ then check if /somepage.php exists
RewriteCond ^/.* $1\.php
# now rewrite /somepage/ as /somepage.php
RewriteRule ^/.*/ $1\.php

but yet I am a beginner, so I could be completely wrong!


2.  I would also like to

rewrite:
    http://username:password@domain.com/protected/archive/(.*)

to:
    http://domain.com/protected/archive/$1

what is the easiest way to do this?


Best Regards,

Scott Taylor




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite simple questions

Posted by Robert Andersson <ro...@profundis.nu>.
Scott Taylor wrote:
> 1.  I would like to refer to all of my pages without the ending and with
> a trailing slash.  for instance, instead of domain.com/somepage.html it
> should be domain.com/somepage/
>
> There may be a variety of different file types in a directory, so it
> would need a RewriteCond statement to find if there was a coresponding
> file type...

Why don't you just create those directories and drop an "index.html" or
"index.php" in them? That will save you a lot of headaches. It would make
your setup less obscure.

> 2.  I would also like to
>
> rewrite:
>     http://username:password@domain.com/protected/archive/(.*)
>
> to:
>     http://domain.com/protected/archive/$1

Not possible. Apache will never get a request like that. The
username:password part will be stripped by the client and in some cases be
inserted in an Authentication header.

If the user types "http://foo:bar@domain.com/protected/archive/xyz" in his
address bar, the client will send a request for "/protected/archive/xyz" to
domain.com. If all you want is redirect or rewrite that to "/archive/xyz",
it is trivial, and is left as an excersice for you :)

Regards,
Robert Andersson


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org