<-
Apache > HTTP Server > �ĵ� > �汾2.2
���� ��л | �������� | ��ƪ���ߣ��𲽹� | ��ҳ�����£�2006��1��7�� | ��ȡ���°汾

��URL���ļ�ϵͳ��ӳ��

���IJ���Apache��θ���URL��ַ��λ���ļ����ļ�ϵͳ�е�λ�á�

top

���ģ���ָ��

top

DocumentRoot

Apache��������λ�ļ���Ĭ�ϲ����ǣ�ȡ��URL·��(��URL���������Ͷ˿ں���IJ���)���ӵ���DocumentRootָ�����ļ�ϵͳ·�����档������������������������Ļ����ļ����ṹ��

����������ж��������������Apache��ʹ���������ַ���֮һ��ʹ��ÿ�����������Լ���DocumentRoot������ļ�ϵͳ·��������ʹ����mod_vhost_alias�ṩ��ָ�����IP��ַ����������̬�ض�λ�ļ���

top

DocumentRoot������ļ�

ʵ��Ӧ���У������б�Ҫ���������DocumentRoot������ļ����з��ʡ��Դˣ�Apache�ṩ�˶��ַ�������Unixϵͳ�У��������ļ�ϵͳ��DocumentRootĿ¼�·��÷��������Է������ⲿ�ļ������ǵ���ȫ���⣬���ַ���������ӦĿ¼��Optionsָ����������FollowSymLinks��SymLinksIfOwnerMatchʱ����Ч��

���⣬ʹ��Aliasָ����Խ��ļ�ϵͳ���κβ���ӳ�䵽����ռ��С����磬�������

Alias /docs /var/web

���԰�URL http://www.example.com/docs/dir/file.htmlӳ��Ϊ/var/web/dir/file.html ��ScriptAliasָ������ƣ�����ʹ����Ŀ��·���µ������ļ�����ΪCGI�ű���

AliasMatch��ScriptAliasMatchָ�����ʵ�ֻ���������ʽ��ƥ����滻�����ṩ���������ԡ����磺

ScriptAliasMatch ^/~([a-zA-Z0-9]+)/cgi-bin/(.+) /home/$1/cgi-bin/$2

����������Խ�http://example.com/~user/cgi-bin/script.cgi ӳ�䵽/home/user/cgi-bin/script.cgi ������֮ΪCGI�ű���

top

�û�Ŀ¼

��Unixϵͳ�У�һ���ض��û�"user"����Ŀ¼ͨ����"~user/"ģ��mod_userdir������������������������ʹ��URL����λ�ڸ��û���Ŀ¼�µ��ļ������磺

http://www.example.com/~user/file.html

���ڰ�ȫԭ�򣬲�Ӧ�ø��������û�ֱ�Ӳ�����Ŀ¼��Ȩ�ޣ���Ӧ�����û���Ŀ¼���½�һ��Ŀ¼���������ļ���������½���Ŀ¼�У�����UserDirָ����߷�������ȱʡ���û�Ŀ¼������"Userdir public_html"����ˣ����������е�URL��ӳ�䵽/home/user/public_html/file.html ������/home/user/ ��/etc/passwdָ�����û���Ŀ¼��

��/etc/passwdû��ָ����Ŀ¼���Ǿ�Ҫ�õ�Userdirָ���������ʽ��

��Щ�˾��÷���"~"(ʱ���ᱻ����Ϊ%7e)�ܱ�Ť��ϣ����������ʽ������û�Ŀ¼����Ȼģ��mod_userdir����֧�֣����ǣ��������滮�������ϵ��û�Ŀ¼�������п�����AliasMatchָ�����ﵽ���Ŀ�ġ����磬���ϣ����http://www.example.com/upages/user/file.htmlӳ�䵽/home/user/public_html/file.html ����������ʹ��AliasMatchָ�

AliasMatch ^/upages/([a-zA-Z0-9]+)/?(.*) /home/$1/public_html/$2

top

URL�ض���

����ָ�ָʾApache���ظ��ͻ��ļ�ϵͳ��ij���ض����ݣ�������ʱ����Ҫ֪ͨ�ͻ������������λ������URL����ʹ�ͻ������µĶ�����URL���������ֻ��Ƴ�Ϊ�ض���(redirection)��������Redirectָ��ʵ�֡����磺���DocumentRoot��Ŀ¼/foo/��ת�Ƶ���/bar/ ����������������ͻ������µ�λ�ã�

Redirect permanent /foo/ http://www.example.com/bar/

��������ض����κ���/foo/��ͷ��URL·����λ��ͬһ��������www.example.com��/bar/ ����Ȼ�������ض����κ�����������������������ԭ�����Ǹ���

Apache���ṩ��RedirectMatchָ����������ӵ��ض������⡣���磬Ҫ�ض����վ����ҳ����������վ�㣬�����������������󣬿����������ã�

RedirectMatch permanent ^/$ http://www.example.com/startpage.html

��һ�ַ����ǣ���ʱ���ض���վ�������ҳ�浽һ���ض�ҳ�棬�磺

RedirectMatch temp .* http://othersite.example.com/startpage.html

top

�������

Apache������Զ���ĵ����뱾�ط�����������ռ��У���ΪWeb����������һ������������Ľ�ɫ(��Զ�̷�����ȡ���ĵ������ظ��ͻ�)���������ֻ��Ʊ���Ϊ�������(reverse proxying)����ͬ�ڱ�׼������ǣ��ڿͻ���������������ĵ��ƺ�ԭ����λ������������������ϡ�

������ʾ�˵��ͻ�����λ��/foo/Ŀ¼�µ��ĵ�ʱ����������internal.example.com��/bar/Ŀ¼��ȡ���ĵ������ظ��ͻ����ƺ��ĵ�ԭ�����ڱ��ط������ϣ�

ProxyPass /foo/ http://internal.example.com/bar/
ProxyPassReverse /foo/ http://internal.example.com/bar/ ProxyPassReverseCookieDomain internal.example.com public.example.com ProxyPassReverseCookiePath /foo/ /bar/

ProxyPassָ��ʹ��������ȷ��ȡ���ĵ���ͬʱ��ProxyPassReverseָ��ı�����ʼ��internal.example.com������ʹָ֮�򱾵ط������ϵ�Ŀ¼��ͬ����ProxyPassReverseCookieDomain��ProxyPassReverseCookieDomainָ���ı��˷��������õ�cookie ��

��Ҫע��ĺ���Ҫ��һ���ǣ���ȡ�ص��ĵ��е������Dz��ᱻ��д�ģ���ˣ��ĵ��е����о���·�����ӻ�ͻ�ƴ�����ƶ�ֱ�Ӵ�internal.example.comȡ�á�һ��������ģ��mod_proxy_html����������дHTML��XHTML���ӡ�

top

URL�����

mod_rewriteģ���ṩ�˸�ǿ���URL��д���棬���Ը���������������������͡�ԴIP��ַ�����������������ύ���ͻ������ݣ�������ʹ���ⲿ���ݿ�������������δ���һ�����󣬲�����ִ����������������ӳ�䣺�ڲ��ض���(aliases)���ⲿ�ض��򡢴������ʵ�ó����õ������ģ�飬��ϸ�����μ���URL��дָ����

top

File Not Found

��URL���ļ�ϵͳ��ƥ��ʧ���Dz��ɱ���ģ������ԭ���ж��֡���ʱ���ĵ���ת���ˣ��Դ��������URL�ض����������û������µ�λ�ã���������Ȼ��Դ�Ѿ�ת�Ƶ��µ�λ�ã�����ԭ������ǩ��������Ȼ��Ч��

��һ�ֳ�����ԭ�����������ַ������HTML�����е�URL��ƴд���ˣ�Apache�ṩ��mod_spelingģ�����������������⣬����ӹ�"File Not Found"���󲢲��������ļ�������ҵ���Ψһ��һ��������ض�������ļ��������ֹһ���������һ�ű������û���

mod_speling��һ�������õ������ǣ������Ժ��Դ�Сд�����ļ����Բ�ע��URL��Сд���û���unix�ļ�ϵͳ��Ϊʵ�á����ǣ�����żȻ��URL��������������������ĸ�������Ϊÿ��"����ȷ"�����󶼽�����URL�ض�������Կͻ���������

������е�Ŭ����ʧ���ˣ�Apache�᷵��һ��������Ϣҳ�棬��״̬��Ϊ"404"(�ļ�û�ҵ�)����ҳ������ȡ����ErrorDocumentָ������������Զ�������ʽ��������Զ��������Ӧ��