T086ѧϰ�� | վ��ѧԺ | �����ĵ� | ���� | Ъ���� | IP��ַ��ѯ | �������� | ���ջ��� | �����ֵ� | ���ù��� | ������Ϣ��ѯ

rewrite ��д���ݶ�URL��ַ����

�� �������ߣ����� ����ʱ�䣺2007-06-04 | ���壺�� �� С��
[����]modrewite ��URL��������һ��Ŀ¼���ļ�������ַ��URL���䣬��ҳ����Ϊ�µ�ַ���ݡ� http://www.test.com/a/b ��ʾ http://www.test.com/test/�����ݣ�URL��ַ������Ϊ www.test.com/a/b�������������Լ����Ը�������...

modrewite ��URL��������һ��Ŀ¼���ļ�������ַ��URL���䣬��ҳ����Ϊ�µ�ַ���ݡ�
http://www.test.com/a/b   ��ʾ http://www.test.com/test/�����ݣ�URL��ַ������Ϊ
www.test.com/a/b
�������������Լ����Ը��������䶯
 
�ο����ӣ�Apache ��д�����ij���Ӧ��

һ��ʵ��ԭ����
      ����Ҫ����2�㣩
      ֻ�е��û���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����
      ���������� 
 
˵����Ϊ�˲��õ�ַURL����д���������ض�����ʹ��apache mod_proxy����ģ���ķ�����������
ʵ�֡�
��������˵һ��mod_proxy
Apache���Ա�����Ϊ����(forward)�ͷ���(reverse)������
����������һ��λ�ڿͻ��˺�ԭʼ������(origin server)֮���ķ�������Ϊ�˴�ԭʼ������ȡ��
���ݣ��ͻ�������������һ��������ָ��Ŀ��(ԭʼ������)��Ȼ��������ԭʼ������ת��������
�����õ����ݷ��ظ��ͻ��ˡ��ͻ��˱���Ҫ����һЩ�ر������ò���ʹ������������
���������ĵ�����;��Ϊ�ڷ���ǽ�ڵľ������ͻ����ṩ����Internet��;������������������
ʹ�û�������(��mod_cache�ṩ)��������ʹ���ʡ�
ʹ��ProxyRequestsָ��ɼ���������������Ϊ�������������ͻ���ͨ��������������վ������
�ؿͻ���������������������ȡ��ȫ��ʩ��ȷ����Ϊ������Ȩ�Ŀͻ����ṩ������
�������������෴�����ڿͻ��˶�����������ԭʼ�����������ҿͻ��˲���Ҫ�����κ��ر�����
�á��ͻ������������������ֿռ�(name-space)�е����ݷ�����ͨ���󣬽��ŷ����������ж���
�δ�(ԭʼ������)ת�����󣬲������õ����ݷ��ظ��ͻ��ˣ�������Щ����ԭ���������Լ���һ
����
���������ĵ�����;�ǽ�����ǽ�����ķ������ṩ��Internet�û����ʡ���������������Ϊ����
�Ķ�̨�������ṩ����ƽ�⣬��Ϊ���˽����ķ������ṩ�������������⣬���������ø߼�URL��
�Ժ͹����������Ӷ�ʹ���ڲ�ͬweb������ϵͳ��webҳ��ͬʱ������ͬһ��URL�ռ��¡�
����ʹ��ProxyPassָ��������(��RewriteRuleָ����ʹ��[P]����Ҳ����)�����÷�������
������Ҫ����ProxyRequestsָ�
����ʾ����
��������
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Deny from all
Allow from internal.example.com
</Proxy>
��������
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar

����mod_rewrite�ľ���ʹ�÷��������������Ͳ���˵�ˣ��뿴�������ӣ�
http://bbs.chinaunix.net/viewthread.php?tid=66521&extra=page%3D2
�ġ���ʼ��װ!!!!!!
��ϸ����������˵������������û�м����ģ�Խ��Խ�������ۻ����dz���Ҫ������
1����װapache2.0
cd apache2.0
./configure --enable-MODULE=shared --enable-so --with-mpm=worker  --enable-
rewrite=shared  --enable-proxy=shared
˵����
--enable-proxy=shared  ����mod_proxyģ��
--enable-rewrite=shared  ����mod_rewriteģ��
���ڱ���mod_rewriteģ�飬�Ҷ�˵���䣺
���������ķ�����rewriteģ���Ѿ�������������./apache2/module/Ŀ¼���ˣ����������ļ�
LoadModuleҲ��������·���ˣ�������ʹ��ʱrewriteȴ������д�����������ֶ�������һ�Σ���
������ͬ��Ҳ�ʺϲ������°�װapache�������ֶ����ӵķ�����

cd Դ����Ŀ¼
find ./ -name mod_rewrite.c
  cd PATH/to/mod_rewrite.c
/usr/local/apache2/bin/apxs -c mod_rewrite.c
/usr/local/apache2/bin/apxs -i -a -n mod_rewrite mod_rewrite.la
 
����������������
Syntax error on line 329 of /usr/local/apache2/conf/httpd.conf:
Can`t loacte API module staructure `mod_rewrite_module` in file
/usr/local/apache2/modules/mod_rewrite.so:/usr/local/apache2/lib/libapr-
0.so.0:undefined symbol:mod_rewrite_module
�޸�http.conf
ԭ����httpd.conf����д��mod_rewrite_module
�ij� rewrite_module
 
��������apache������������module rewrite_module is built-in and can`t be loaded
��ʾģ�����ڽ��ģ������ٵ���
������
2���޸������ļ�
vi conf/httpd.conf
�����������ݣ�
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
����mod_proxy��������
NameVirtualHost 192.168.0.203:80
<VirtualHost 192.168.0.203:80>
    ServerAdmin [email protected]
    DocumentRoot /test
    ServerName www.test.com
    ErrorLog logs/ip-error_log
RewriteEngine on
RewriteCond %{REQUEST_URI} /[^&]+/b/
RewriteCond %{REQUEST_URI} !/test/
RewriteCond %{HTTP_HOST} ^www.test.com [NC]
RewriteRule ^/(.*) http://www.test.com/test/ [P,L]
</VirtualHost>
�⼸�������͹�������˼�ǣ���������www.test.com  ��[^&]+��ʾ�����ַ������Һ�����URIΪ
a/b/��ʽ��������www.test.com/test/ ������������www.test.com/test/������ת��[P]������
������Ҫ��ʹ�÷���������ʽӦ���û�������
���������⼸�������ǿ���ʵ��ǰ����������

  • ת����ע����Դ��ITѧϰ�� ��ַ��http://www.t086.com/ �����������Ƽ�������
  • �ر������� ��վ�������ر�������ֹת�ص�ר�������������¿�������ת�أ���������ע��������ԭʼ���ߡ����°�Ȩ������ԭʼ�������С����ڱ���վת�����µĸ��˺���վ�����DZ�ʾ������л�⡣������վת�ص������а�Ȩ��������ϵ���ǣ����ǻᾡ�����Ը�����
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
  • ��
������ѯ Health Check Gulangyu
© 2017 T086ѧϰ�� - T086.com(ԭitlearner.com)
RunTime:18.98ms QueryTime:7