View previous topic :: View next topic |
Author |
Message |
Jesore Apprentice
Joined: 17 Jul 2002 Posts: 232 Location: Nürnberg Germany
|
Posted: Mon Dec 29, 2003 10:54 pm Post subject: Tiny apache question |
|
|
It really is a tiny question. When I access a subdirectory via a browser on my webserver
Code: | http://localhost/test/ |
is there a way to leave out the last slash, also ...test insted of test/ ?
I can remember to add a slash, but I got kicked by several people who wanted to access my content.
Thanks
Jesore |
|
Back to top |
|
|
slais-sysweb Apprentice
Joined: 14 Jun 2002 Posts: 221 Location: London
|
Posted: Tue Dec 30, 2003 1:40 am Post subject: |
|
|
It should work without the final slash by default with apache2 and gentoo, provided you have enabled world read and execute permissions on the directories. If it is not happening then check the /etc/apache2/conf/commonapache2.conf for MultiViews
Code: |
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options -Indexes FollowSymLinks MultiViews
|
_________________ --
djc
sysweb SLAIS UCL |
|
Back to top |
|
|
Jesore Apprentice
Joined: 17 Jul 2002 Posts: 232 Location: Nürnberg Germany
|
Posted: Tue Dec 30, 2003 4:33 pm Post subject: |
|
|
Code: | <Directory "/var/www/localhost/htdocs">
Options Indexes Multiviews
AllowOverride None
Order allow,deny
Allow from all
</Directory> |
I've put this as a test in the file you mentioned, the test dir (directly below htdocs) is world readable and still the same problem. I've read a bit about Multiviews - are you really sure this is the right option?
Btw. this is a stock gentoo install with apache2 - before that I've changed nothing in the config files.
Jesore
edit* Hey, this is my 100th post |
|
Back to top |
|
|
slais-sysweb Apprentice
Joined: 14 Jun 2002 Posts: 221 Location: London
|
Posted: Tue Dec 30, 2003 11:19 pm Post subject: |
|
|
Jesore wrote: |
bit about Multiviews - are you really sure this is the right option?
Btw. this is a stock gentoo install with apache2 - before that I've changed nothing in the config files.
|
The code should be as shown in the stock install anyway. I assumed it was MultiViews that was relevant as some months ago I did a lot of experimenting to set up a new site with such features and MultiViews was certainly a factor. Unfortunately I had too many other jobs pressing to be done and I never got around to writing up the results. You can use mod_rewrite which will certainly do the job but may require (as I found) a lot of experiment and testing to get the required result.
See:
http://httpd.apache.org/docs/mod/mod_rewrite.html
and in particular "Trailing Slash Problem" in
http://httpd.apache.org/docs/misc/rewriteguide.html
This can be put in a .htaccess file but note that it is far more efficient to do the rewrite in the config file
Quoting from the Guide:
Code: | RewriteEngine on
RewriteBase /~quux/
RewriteRule ^foo$ foo/ [R]
|
Looking at the code I wrote for http://www.slais.ucl.ac.uk I see that I had to turn MultiViews off, but that may be a consequence of the rather elaborate set of rewrite rules I used. I post it here as it may be useful; and oneday given the right sort of tuits I might even write up the explanation of how it all works. Possibly even before I need to do some maintenance
The purpose of all this is to rewrite URLs so that, for example:
http://www.slais.ucl.ac.uk/teaching-ARM-P002 or the fake directory form http://www.slais.ucl.ac.uk/teaching/ARM/P002 will translate to the real .php page which is
http://www.slais.ucl.ac.uk/teaching.php?progID=ARM&modID=P002. The advantage: users dont have to rember or quote the ugly version and possibly (if you believe search-engine voodoo) be easier to search.
In /etc/apache2/conf/apache2.conf
Code: | ### Global Configuration
###
# Splitting up apache2.conf into two files makes it easier to support
# multiple configurations on the same serer. In commonapache2.conf
# you keep directives that apply to all implementations and in this
# file you keep server-specific directives.
# SLAIS config
Include conf/SLAISwww.conf[/conf]
|
In SLAISwww.conf
Code: |
sysweb@wirth:sysweb $ cat /etc/apache2/conf/SLAISwww.conf
# slais-www@... 2003-11-07
# WIRTH.slais.ucl.ac.uk www.slais.ucl.ac.uk
RewriteEngine on
RewriteMap UC int:toupper
RewriteMap LC int:tolower
RewriteMap PROGID txt:/home/httpd/lib/PROGID.txt
RewriteMap STAFFID txt:/home/httpd/lib/STAFFID.txt
RewriteMap DIR2PHP txt:/home/httpd/lib/DIR2PHP.txt
# skip all this if filename with extension
RewriteRule .php$ - [L]
# known php filename
RewriteRule ^/teaching$ /teaching.php [L]
RewriteRule ^/teaching[/\-](ARM|ECP|LIS|MSC|RAM)$ \
/teaching.php?progID=${UC:$1} [NC,QSA,L]
RewriteRule ^/teaching[/\-](ARM|ECP|LIS|MSC|RAM)[/\-][P]([0-9]{3})$ \
/teaching.php?progID=${UC:$1}&modID=P$2 [NC,QSA,L]
RewriteRule ^/teaching[/\-](ARM|ECP|LIS|MSC|RAM)[/\-]([a-zA-Z]+)$ \
/teaching.php?progID=${UC:$1}&pageID=${LC:$2} [NC,QSA,L]
RewriteRule ^/research[/\-]?([a-z]*)$ \
/research.php?pageID=${LC:$1} [NC,QSA,L]
RewriteRule ^/staff[/\-]?([a-z0-9]{0,3})$ \
/staff.php?staffID=${LC:$1} [NC,QSA,L]
RewriteRule ^/search[/\-]?([a-z_]*)$ \
/search.php?pageID=${LC:$1} [NC,QSA,L]
RewriteRule ^/index[/\-]?([a-z]*)$ \
/index.php?pageID=${LC:$1} [NC,QSA,L]
# Full_Name to staffID
RewriteCond ${STAFFID:$1} !=""
RewriteRule ^/([A-Za-z_]+)$ \
/staff.php?staffID=${STAFFID:$1} [QSA,L]
# if /3 char/* try progID
RewriteRule ^/(ARM|ECP|LIS|MSC|RAM)$ \
/teaching.php?progID=${UC:$1} [NC,QSA,L]
RewriteRule ^/(ARM|ECP|LIS|MSC|RAM)[/\-][P]([0-9]{3})$ \
/teaching.php?progID=${UC:$1}&modID=P$2 [NC,QSA,L]
RewriteRule ^/(ARM|ECP|LIS|MSC|RAM)[/\-]/([a-zA-Z]+)$ \
/teaching.php?progID=${UC:$1}&pageID=${LC:$2} [NC,QSA,L]
# possible synonyms for progID
#RewriteCond ${PROGID:$1} !=""
#RewriteRule ^test/([A-Za-z_]+)$ test.php?progID=${PROGID:$1} [QSA,L]
#RewriteRule ^test/([A-Za-z_]+)/[Pp]([0-9]{3})$ test.php?progID=${PROGID:$1}&modID=P$2 [QSA,L]
#RewriteRule ^test/([A-Za-z_]+)/([a-zA-Z]+)$ test.php?progID=${PROGID:$1}&pageID=${LC:$2} [QSA,L]
# having lost multiviews we need to cover the case of filename sans .etc
RewriteCond /home/httpd/www/$1.php -f
RewriteRule ^/([a-zA-Z0-9\.\-_]+[^/])$ /$1.php [L]
RewriteCond /home/httpd/www/$1.html -f
RewriteRule ^/([a-zA-Z0-9\.\-]+[^/])$ /$1.html [L]
# otherwise assume pageID
RewriteRule ^/([a-z]+)$ /index.php?pageID=${LC:$1} [NC,QSA,L]
|
This is in the main commonapache2.conf
Code: | <Directory /home/httpd/www>
Options -Indexes FollowSymLinks -MultiViews
AllowOverride All
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
|
The web directory contains
Code: | sysweb@wirth:sysweb $ ls /home/httpd/www
index.php research.php staff.php search.php teaching.php
|
An example of the rewrite map:
Code: |
sysweb@wirth:sysweb $ cat /home/httpd/lib/STAFFID.txt
# slais-www@.... 2003-11-05
# ~httpd/lib/STAFFID.txt
# WIRTH.slais.ucl.ac.uk www.slais.ucl.ac.uk
# Apache RewriteMap
DJC djc
SYSWEB djc
| and
Code: | sysweb@wirth:sysweb $ cat /home/httpd/lib/PROGID.txt
# slais-www@... 2003-11-05
# ~httpd/lib/PROGID.txt
# WIRTH.slais.ucl.ac.uk www.slais.ucl.ac.uk
# Apache RewriteMap
arm ARM
ecp ECP
lis LIS
msc MSC
ram RAM
rami RAM
ARM ARM
ECP ECP
LIS LIS
MSC MSC
RAM RAM
RAMI RAM
| [/url] _________________ --
djc
sysweb SLAIS UCL |
|
Back to top |
|
|
Jesore Apprentice
Joined: 17 Jul 2002 Posts: 232 Location: Nürnberg Germany
|
Posted: Sat Jan 03, 2004 10:54 am Post subject: |
|
|
Thanks for your help - it works now (have bee away of my pc for a few days - sorry for the delayed answer).
Jesore |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|