Apache HTTP Server �汾2.2
���IJ���Apache��θ���URL��ַ��λ���ļ����ļ�ϵͳ�е�λ�á�
���ģ�� | ���ָ�� |
---|---|
Apache��������λ�ļ���Ĭ�ϲ����ǣ�ȡ��URL·��(��URL���������Ͷ˿ں���IJ���)���ӵ���DocumentRoot
ָ�����ļ�ϵͳ·�����档������������������������Ļ����ļ����ṹ��
����������ж��������������Apache��ʹ���������ַ���֮һ��ʹ��ÿ�����������Լ���DocumentRoot
������ļ�ϵͳ·��������ʹ����mod_vhost_alias
�ṩ��ָ�����IP��ַ����������̬�ض�λ�ļ���
ʵ��Ӧ���У������б�Ҫ���������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�ű���
��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
����ָ�ָʾ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
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���ӡ�
mod_rewrite
ģ���ṩ�˸�ǿ���URL��д���棬���Ը���������������������͡�ԴIP��ַ�����������������ύ���ͻ������ݣ�������ʹ���ⲿ���ݿ�������������δ���һ����������ִ����������������ӳ�䣺�ڲ��ض���(aliases)���ⲿ�ض��������ʵ�ó����õ������ģ�飬��ϸ�����μ���URL��дָ����
��URL���ļ�ϵͳ��ƥ��ʧ���Dz��ɱ���ģ������ԭ���ж��֡���ʱ���ĵ���ת���ˣ��Դ��������URL�ض����������û������µ�λ�ã���������Ȼ��Դ�Ѿ�ת�Ƶ��µ�λ�ã�����ԭ������ǩ��������Ȼ��Ч��
��һ�ֳ�����ԭ�����������ַ������HTML�����е�URL��ƴд���ˣ�Apache�ṩ��mod_speling
ģ�����������������⣬����ӹ�"File Not Found"�����������ļ�������ҵ���Ψһ��һ��������ض�������ļ��������ֹһ���������һ�ű������û���
mod_speling
��һ�������õ������ǣ������Ժ��Դ�Сд�����ļ����Բ�ע��URL��Сд���û���unix�ļ�ϵͳ��Ϊʵ�á����ǣ�����żȻ��URL��������������������ĸ�������Ϊÿ��"����ȷ"����������URL�ض�������Կͻ���������
������е�Ŭ����ʧ���ˣ�Apache�᷵��һ��������Ϣҳ�棬��״̬��Ϊ"404"(�ļ�û�ҵ�)����ҳ������ȡ����ErrorDocument
ָ������������Զ�������ʽ��������Զ��������Ӧ��