Apache重写规则

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Apache重写规则相关的知识,希望对你有一定的参考价值。

  1. <IfModule rewrite_module>
  2. Options +FollowSymLinks
  3. RewriteEngine ON
  4. RewriteLog /Developer/Servers/apache2/logs/mod_rewrite.log
  5. RewriteLogLevel 2
  6.  
  7. # BlogCFC URL Rewrite Rules
  8. #RewriteRule ^/([A-Za-z0-9-]+)/projects/blog/([w]+)/index.cfm/(.*)$ /$1/projects/blog/$2/index.cfm?blogParams=$3 [PT,L]
  9. # Blog URL Rewrite Rules
  10. RewriteRule ^/([A-Za-z0-9-]+)/projects/blog/([w]+)/index.cfm/(.*)$ /$1/projects/blog/$2/index.cfm?blog_param=$3 [R]
  11.  
  12. RewriteCond %{QUERY_STRING} ^blog_alias=([w]+)(.*)$ [NC]
  13. RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/index.cfm /$1/projects/$2/%1/?%2 [R]
  14. # If trailing slash is not provided...add trailing slash, and go to default site
  15. RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)$ /$1/projects/$2/default/ [R]
  16. # If site is not provided...go to default site
  17. RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/$ /$1/projects/$2/default/ [R]
  18. # If site is provided, but trailing slash is not provided...add trailing slash, and go to site
  19. RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([w]+)$ /$1/projects/$2/$3/ [R]
  20. # If loading an include...pass on through
  21. RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([w]+)/includes/(.*)$ /$1/projects/$2/includes/$4 [QSA,PT,L]
  22. RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([w]+)/admin/(.*)$ /$1/projects/$2/admin/$4?blog_alias=$3 [QSA,PT,L]
  23. # site is provided, and all is good...pass on through
  24. #RewriteRule ^/([A-Za-z0-9-]+)/(blog[0-9]*)/([w]+)/(.*)$ /$1/$2/index.cfm?blog_alias=$3 [QSA,PT,L]
  25. RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([w]+)/(.*)$ /$1/projects/$2/$4?blog_alias=$3 [QSA,PT,L]
  26.  
  27. # CMS URL Rewrite Rules
  28. RewriteCond %{QUERY_STRING} ^site_alias=([w]+)(.*)$ [NC]
  29. RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/index.cfm /$1/projects/$2/%1/?%2 [R]
  30. # If trailing slash is not provided...add trailing slash, and go to default site
  31. RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)$ /$1/projects/$2/default/ [R]
  32. # If site is not provided...go to default site
  33. RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/$ /$1/projects/$2/default/ [R]
  34. # If site is provided, but trailing slash is not provided...add trailing slash, and go to site
  35. RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([w]+)$ /$1/projects/$2/$3/ [R]
  36. # If loading an asset...pass on through
  37. RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([w]+)/assets/(.*)$ /$1/projects/$2/assets/$4 [QSA,PT,L]
  38. # site is provided, and all is good...pass on through
  39. RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([w]+)/(.*)$ /$1/projects/$2/index.cfm?site_alias=$3 [QSA,PT,L]
  40. </IfModule>

以上是关于Apache重写规则的主要内容,如果未能解决你的问题,请参考以下文章

apache重写规则可以进入httpd.conf吗

花括号( 和 )从 Apache 到 Nginx 重写规则。

Apache rewrite地址重写

PHP/Apache:用 .htaccess 重写规则

使用 apache 重写规则的问题

Apache URL重写规则