本文介绍了简单的mod_rewrite重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

了大量的研究和一些帮助后,我设法学习了一下如何国防部重写工作......谁能告诉我有什么错我的code波纹管?

  ######重定向所有静态文件的静态域
的RewriteCond%{REQUEST_URI} ^ / \(+)。(GIF | PNG | JPG | JPEG | JFIF | BMP | CSS | JS)$ [NC]
重写规则^(。*)$ http://static.example.com/$1 [R = 301,L]

######裸体重定向到www
的RewriteCond%{HTTP_HOST} ^ example.com $ [NC]
重写规则(。*)http://www.example.com/$1 [R = 301,L]

###### IP重新定向到www
的RewriteCond%{HTTP_HOST} ^ 100 \ .100 \ .100 \ .100 $
重写规则^(。*)$ http://www.example.com/$1 [R = 301,L]

######重定向从静态域的所有非静态文件(因为剩下的)到www
的RewriteCond%{REQUEST_FILENAME} \!(GIF | PNG | JPG | JPEG | JFIF | BMP | CSS | JS)$ [NC]
重写规则^(。*)$ http://www.example.com/$1 [R = 301,L]
 

谢谢!

此外,有什么区别:

 的RewriteCond%{REQUEST_URI} ^ / \!(+)。(GIF | PNG | JPG | JPEG | JFIF | BMP | CSS | JS)$ [NC]
 

 的RewriteCond%{REQUEST_FILENAME} \!(GIF | PNG | JPG | JPEG | JFIF | BMP | CSS | JS)$ [NC]
 

解决方案

试试这个的.htaccess:

  ######重定向所有静态文件的静态域
的RewriteCond%{HTTP_HOST} ^(WWW \)?例如\ .COM $ [NC]
。重写规则\(?GIF | PNG | JPE G | JFIF | BMP | CSS | JS)$ HTTP://static.example.com% {REQUEST_URI} [R = 301,L,NC]

######裸体重定向到www
的RewriteCond%{HTTP_HOST} ^例如\ .COM $ [NC,OR]
的RewriteCond%{HTTP_HOST} ^ 100 \ .100 \ .100 \ .100 $
重写规则^ HTTP://www.example.com% {REQUEST_URI} [R = 301,L]

######重定向从静态域的所有非静态文件(因为剩下的)到www
的RewriteCond%{HTTP_HOST} ^静态\。 [NC]
重写规则\(GIF | PNG | JPE G | JFIF | BMP | CSS | JS?)$ HTTP:!//www.example.com% {REQUEST_URI} [R = 301,L,NC]
 

After a lot of research and some help, I managed to learn a bit of how mod rewrite works... Can someone tell me what's wrong with my code bellow?

######redirect all static files to the static domain
RewriteCond %{REQUEST_URI} ^/(.+)\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]
RewriteRule ^(.*)$ http://static.example.com/$1 [R=301,L]

######redirect naked to www
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

######redirect IP to www
RewriteCond %{HTTP_HOST} ^100\.100\.100\.100$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

######redirect all non static files from static domain (because that remains) to www
RewriteCond %{REQUEST_FILENAME} !\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Thanks!

Also, what's the difference between:

RewriteCond %{REQUEST_URI} !^/(.+)\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]

and

RewriteCond %{REQUEST_FILENAME} !\.(gif|png|jpg|jpeg|jfif|bmp|css|js)$ [NC]
解决方案

Try this .htaccess:

######redirect all static files to the static domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule \.(gif|png|jpe?g|jfif|bmp|css|js)$ http://static.example.com%{REQUEST_URI} [R=301,L,NC]

######redirect naked to www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^100\.100\.100\.100$
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]

######redirect all non static files from static domain (because that remains) to www
RewriteCond %{HTTP_HOST} ^static\. [NC]
RewriteRule !\.(gif|png|jpe?g|jfif|bmp|css|js)$ http://www.example.com%{REQUEST_URI} [R=301,L,NC]

这篇关于简单的mod_rewrite重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:10