You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Robert Cailliau <ro...@cailliau.org> on 2013/05/25 17:06:38 UTC

[users@httpd] option indexes and rewrite

I'm new to httpd.conf (apache 2.0)
I want the server to respond in one of two ways to a request that looks like
a directory.
e.g. if the request is *http://localhost/a/b/c/*
then: (1) if a file with name "* c-en.html*" exists inside directory *c*,
then it should serve that,
(2) if that file does not exist, it should serve the directory listing of
directory *c*.
(note the space in front of  c-en.html, but I don't think it's relevant)

I wrote:

	RewriteEngine on
	RewriteCond /$1/$2/\ $2-en.html !-f
	RewriteRule ^(.*)/([a-z|A-Z|0-9|-|\ ]+)/?$ $1/$2/\ $2-en.html [L]

	Options Indexes

but either the rewrite rule works or the indexes work, but not the second if
the first fails.
I also do not understand:
(a) why I need to use !-f instead of just -f.
(b) why I need a / to start the RewriteCond.
Thanks for any help.



--
View this message in context: http://apache-http-server.18135.x6.nabble.com/option-indexes-and-rewrite-tp5005951.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: option indexes and rewrite

Posted by Robert Cailliau <ro...@cailliau.org>.
Hi Pete,
  Thank you for your fast reply:

>	I would use DirectoryIndex and mod_autoindex for this and certainly
>would not go anywhere near mod_rewrite.
>
>         DirectoryIndex	" c-en.html"

No, that does alas not achieve my goal at all.
In my request I could of course not give a long explanation for the rationale.
It's all about my own personal documents.
I'm moving towards "liberating" my personal files from proprietary 
formats and use web technology instead. So far I have achieved this 
for everything except spreadsheets.
Each document now is a folder: in the folder sits an html file plus 
all the resources (jpeg images, svg drawings,...) that it uses.  This 
is great, works fine and is future-proof. But I do not want to look 
at a document by typing (or linking) to, say,

   .../A long document name/ A long document name.html

but just by

   .../A long document name/

Hence the rewrite rule: it takes the directory name and makes the 
html name from it.

I also always want the html file to be the first in the directory 
listing when I look at the folder in the file system, and have the 
resources follow later in the list, rather than having to hunt for 
the file amidst loads of resources.  Hence the leading space.
It really works like a dream!

The question I posed was:

If there is no html file in a directory (at least not one that 
corresponds to the name of the directory), then I want just the 
directory listing.  And it is that which does not seem to work.  The 
behaviour I am after is simple:

(1) find the html file that corresponds to the requested directory 
name and display that,
(2) if it does not exist, display the directory listing instead.

(1) works perfectly, it's when it fails that I do not get (2).

I'm running on Snow Leopard, and in fact I do have Apache version 
2.2.22 built 12 July 2012, sorry about the wrong version number.  But 
I don't think that matters to the problem.

When the rewrite rule fails, I want to get the index.  I would be 
surprised if there were no way of telling the server to just get on 
with Option +Indexes in case the rule fails.  But I did not find out 
how...

>         Options +Indexes
>
>I'd humbly suggest however that you try to avoid filenames with leading
>spaces.  As you are new to it, it is also worth pointing out that Apache
>2.0 is deprecated in favour of 2.2 or 2.4.

Yes, right, so I was wrong about my server's version number.

Best,
Robert.




--
View this message in context: http://apache-http-server.18135.x6.nabble.com/option-indexes-and-rewrite-tp5005951p5005954.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.

Re: [users@httpd] option indexes and rewrite

Posted by Pete Houston <ph...@openstrike.co.uk>.
I would use DirectoryIndex and mod_autoindex for this and certainly
would not go anywhere near mod_rewrite.

	DirectoryIndex	" c-en.html"
	Options +Indexes

I'd humbly suggest however that you try to avoid filenames with leading
spaces.  As you are new to it, it is also worth pointing out that Apache
2.0 is deprecated in favour of 2.2 or 2.4.

HTH,

Pete
-- 
Openstrike - improving business through open source
http://www.openstrike.co.uk/ or call 01722 770036 / 07092 020107