Apache ��д�����ij���Ӧ�� (rewrite)
����ּ���ṩ������Apache��д����������һЩ������URL��д���������⣬ͨ��������
ʵ�����û�һЩʹ����д�����Ļ���������������
��:Ϊʲô��Ҫ����д������
һ����վ�������dz�����Ҫ����internet���ṩ���ض����в��ϵظ��º�ά��������
ʱת�Ƶ���������������ά����������֯Ŀ¼�ṹ���任URL�����ı䵽�µ������ȵȣ�
��Ϊ���ÿͻ����������ܵ��κ�Ӱ�죬���õķ�������ʹ��Apache Rewrite Rule(��д
����)��
��: ��д���������÷�Χ
1) ����ʹ����Apache�������ļ�httpd.conf��
2) ����ʹ����httpd.conf�ﶨ������������������
3) ����ʹ���ڻ���Ŀ¼�Ŀ�Խ�����ļ�.htaccess��
��:��д������Ӧ������
ֻ�е��û���WEB�������ձ�������ij̨WEB��������Apache��̨������̨WEB����������
�����������������ļ��������������û��������������ٸ����û�����������������
URI��������д�������Ҹ���ʵ�ʵ�����·������.htaccess�е���д����������������
�����ݴ��ظ��û�������Ӧ���������֣�
1) ���������������ݵ��ⲿ�ض���(Redirect)����һ��URL��
���������ٴ����µ�URI��������(R=301����R=302����ʱ�Ļ������õ��ض���)
�磺һ����վ��������URL�ͱ���URL���Ա���URL�����ض���������URL��������վ�Ļ�
�����µ�����
���Ѿɵ������ض������µ�����(Redirect)
2) Ҳ��������Apache�ڲ����������������µ������ͻظ��ͻ�[P,L]
����Apache�ڲ�������д����URI�ڲ�ͨ������ģ���������ݲ��ͻ����ݸ��ͻ������ͻ�
����������
��֪�����������е�URI���ᱻ��д����ʵ�����ݱ�Apache������д��������URI�õ���
�磺�ڹ�˾����ǽ�����е�Apache�������ִ�����д���������ڲ������ϵ�WEB����
����������
��:���������������
���Ǽٶ��ڱ���Apacheʱ�Ѿ���mod_rewrite������ģ�飬ȷ������httpd.conf����
LoadModule rewrite_module libexec/mod_rewrite.so
������Addmodule����
Addmodule mod_rewrite.c
������ʹ����д������
���ⲿ��������Apache��Apache������д�����еĶ�������д���û�������ָ��������
URI����������д��URI�������ض���������������������һ�������������Ǵ���������д
����URI��������ģ���������յ�����(Content),�����������ͻظ���������
��: ��ʱʹ��.htaccess�е���д�������壿
�����������ĵ���վ�������ڵķ�����û�й���ԱȨ�ޣ�����������վ����ISP�ķ�����
���йܵȵ������£�������д�������ļ���Ȼ�������Զ�����WEBվ���������ڵ�Ŀ¼
��дȨ�ޣ��������������Լ���.htaccess
�ļ��ﵽͬ����Ŀ�ġ�������Ҫȷ���������ļ��ж�������վ���ڵ�Ŀ¼��������������
��:
Options Indexes FollowSymLinks
AllowOverride all
��������.htaccess���Ṥ����
��: Ӧ�þ���
�ٶ�Apache�����밲װ������192.168.1.56��/usr/local/apache/ Ŀ¼���棬���DZ�
��������д�ʹ���ģ�顣
1) ����Apache�µ�ij��Ŀ¼��ʹ�öԸ�Ŀ¼���κ��������ض�������һ���ļ���
a> httpd.conf��ʵ�ַ���
���Ƿ������IJ��ֵ�/usr/local/apache/conf/httpd.conf
options Indexes followsymlinks
allowoverride all
rewriteengine on
rewritebase /
rewriterule ^(.*)$ index.html.en [R=301]
ע��rewriteengine on Ϊ��д���濪�أ�������Ϊoff,���κ���д�������彫����Ӧ
�ã��ÿ��ص���һ�ô���������Ϊ����ʱ�õ���д����������Ϊoff��������Apache��
�ɣ����ؽ�����һ��������д����ע�͵���
rewritebase / ��������������������rewriterule�����б���д���IJ���(�˴�Ϊ�ļ�
��index.html.en)ǰ��û��/����������Ŀ¼������������rewritebase�����Ķ���Ҳ��
��/usr/local/apache/htdocs/index.html.en,�����������˴�û��rewritebase /��
һ�������д��
http://192.168.1.56/usr/local/apache/htdocs/manual/index.html.en ����Ȼ��
����ȷ�ġ�
������������Ҳ���Բ���rewritebase / , ����Ϊ
rewriteengine on
rewriterule ^(.*)$ /index.html.en [R=301]
����
rewriteengine on
rewriterule ^(.*)$ http://192.168.1.56/index.html.en [R=301]
b> .htaccess��ʵ�ַ���
�����ȷ������IJ��ֵ�httpd.conf
options Indexes followsymlinks
allowoverride all
Ȼ���������IJ��ֵ�/usr/local/apache/htdocs/manual/.htaccess��
rewriteengine on
rewritebase /
rewriterule ^(.*)$ index.html.en [R=301]
ע�����ļ�.htaccess�������κθĶ�����Ҫ������Apache.
�ʣ�Ҫ�ǰ�����manualĿ¼�ض������û�jephe���Լ�����Ŀ¼�أ�
��������.htaccess������
rewriteengine on
rewritebase /~jephe/
rewriterule ^(.*)$ $1 [R=301]
����manualĿ¼���κ��ļ����������ض�����~jepheĿ¼����ͬ�ļ���������
2) ת��www.username.domain.com�Ķ���username����ҳ����Ϊ
www.domain.com/username
����HTTP/1.1����������һ��Host: HTTPͷ���������������Ĺ�������д
http://www.username.domain.com/anypath �� /home/username/anypath
Rewriteengine on
rewritecond %{HTTP_HOST} ^www.[^.]+.host.com$
rewriterule ^(.+) %{HTTP_HOST}$1 [C]
rewriterule ^www.([^.]+).host.com(.*) /home/$1$2
ע��
rewritecond ������д�����������涨�����������Ż�Ӧ����������д������
rewritecond�и��ֱ���
�������������ĵ���
3) ����ǽ�ϵ���д���������ڲ������Ϸ�������������
NameVirtualhost 1.2.3.4
servername www.domain.com
rewriteengine on
proxyrequest on
rewriterule ^/(.*)$ http://192.168.1.3/$1 [P,L]
ע�����ⲿ����������www.domain.comʱ��������IP��ַ1.2.3.4 ,Apache ����
mod_rewrite����ת����
http://192.168.1.3/$1���ٽ��ɴ���ģ��mod_proxy�õ����ݺ����ͻ��û�����������
4) ����Ԥ���趨��ת��MAP��������д rewritemap
ת��www.domain.com/{countrycode}/anypath ��Map���й涨��URI,��������������
�еĶ���
rewritelog /usr/local/apache/logs/rewrite.log
rewriteloglevel 9
rewriteengine on
proxyrequest on
rewritemap sitemap txt:/usr/local/apache/conf/rewrite.map
rewriterule ^/([^/]+)+/(.*)$ http://%{REMOTE_HOST}::$1 [C]
rewriterule (.*)::([a-z]+)$ ${sitemap:$2|http://h.i.j.k/} [R=301,L]
�ļ�/usr/local/apache/conf/rewrite.map����������:
sg http://a.b.c.d/
sh http://e.f.g.h/
ע�� ���û�����http://www.domain.com/sg/anypathʱ����дΪ
http://a.b.c.d/anypath .
����Ҫ����ʱ����rewritelog and rewriteloglevel 9����,9Ϊ���õ������ĵ���
��Ϣ
��СΪ1����С�ĵ�����Ϣ��Ĭ��Ϊ0��û�е�����Ϣ��
sitemap�����${sitemap: LookupKey | Defaultvalue} ,��Щ���ϰ�$д����%�Ǵ�
���ġ�
- ת����ע����Դ��ITѧϰ�� ��ַ��http://www.t086.com/ �����������Ƽ�������
- �ر������� ��վ�������ر�������ֹת�ص�ר�������������¿�������ת�أ���������ע��������ԭʼ���ߡ����°�Ȩ������ԭʼ�������С����ڱ���վת�����µĸ��˺���վ�����DZ�ʾ������л�⡣������վת�ص������а�Ȩ��������ϵ���ǣ����ǻᾡ�����Ը�����
- ������������������̸�����ɶ��ر�
- ��������������ѡʳƷ����2020�ļ��ȵ�Ͷ�ʲ��Ժ���������
- �����ڵ�����֤50���ƴ�50����ָ֤�������Ĺ���
- ����֤50����Щ��Ʊ_��֤50Ȩ����������
- ������300����֤50����֤500��ָ��2019���ڶ��ζ��ڵ���������
- ������300��ֵ/�ɳ�ָ�����Ʒ����������й�ƽ��Ȩ���½�
- ����ָ֤��������֤50��ָ��������
- ����ָ֤��������֤����ָ��������
- ����ָ֤��������֤100ָ��������
- ����ָ֤����������300ָ��������