apache_conf Apache上的缓存控制标头

添加到.htaccess文件的顶部。

cache-control-headers
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Cache-Control "max-age=2592000, public"
</filesMatch>

apache_conf 重定向htaccess

.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^nous-joindre/?$ https://decodesign.ca/contact/ [R=301,L]
RewriteRule ^realisations/deco-du-liseron/?$ https://decodesign.ca/realisations/ [R=301,L]
RewriteRule ^realisations/refacing-rachelle/?$ https://decodesign.ca/realisations/ [R=301,L]
RewriteRule ^(.*)$ https://decodesign.ca/ [R=301,QSA,L]

apache_conf nginx的路由重定向

nginx.rewrite
location / { 
  if ($http_host !~ "m.xxx.cn"){
    rewrite ^/web/(.*)/bdu(\d?)\.htm(.*)$ /rewrite.php?custom_dir=$1&bdu_num=$2 last;
  }
  rewrite ^/seo_web/(.*)/index\.html(.*)$ /seo_web/replace.php?custom_dir=$1;
}

apache_conf htaccessキャッシュを有效化

htaccess
キャッシュを有効化して、WordPressサイトを高速化する。
.htaccessの先頭に以下を追加します。

# キャッシュを有効にする
Header set Cache-Control "max-age=2628000, public"

# キャッシュ設定
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>

# ファイル圧縮設定
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
</IfModule>

apache_conf IE10 VM主机文件

将其放入VirtualBox VM的hosts文件中

hosts.conf
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
	127.0.0.1       localhost
	::1             localhost

	10.0.2.2	outer
	10.0.2.2	localhost
	192.168.33.34	boarshead.local
	192.168.33.34	mattr.local

apache_conf 虚拟主机配置

vhost.conf
<VirtualHost *:80>
    ServerName site.local
    DocumentRoot /vagrant/Sites/giraud/site/index.html

    <Directory />
        AllowOverride All
        DirectoryIndex index.html
        SetEnv AppEnvironment development

        <Files *.pdf>
            AddType application/octet-stream .pdf
            ForceType application/pdf
            Header set Content-Disposition attachment
        </Files>
    </Directory>

    ErrorLog /var/log/httpd/site.local-error.log
    CustomLog /var/log/httpd/site.local-access.log combined
</VirtualHost>

apache_conf PHP扩展剥离器

使用.htaccess在Apache上删除.php扩展名

strip-php-extensions
# ------------------------------------------------------
# strip .php files of file extension
# ------------------------------------------------------
# rewrite strictly for files ending in .php
# Instead of your sites files as this => domain-name.com/file.php
# Rewrite so users can do this instead => domain-name.com/file

<IfModule mod_rewrite.c>
   RewriteCond %{REQUEST_FILENAME}.php -f
   RewriteRule ^(.*)$ $1.php [L]
</IfModule>

apache_conf SS3模板调试

SS3模板调试

config.yml
---
Only:
  environment: 'dev'
---
SSViewer:
  source_file_comments: true

apache_conf 常见.htaccess重定向

常见.htaccess重定向

.htaccess
#301 Redirects for .htaccess

#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html

#Redirect an entire site:
Redirect 301 / http://www.domain.com/

#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/

#Redirect a sub folder to another site
Redirect 301 /subfolder http://www.domain.com/

#This will redirect any file with the .html extension to use the same filename but use the .php extension instead.
RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php

##
#You can also perform 301 redirects using rewriting via .htaccess.
##

#Redirect from old domain to new domain
RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

#Redirect to www location
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

#Redirect to www location with subdirectory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/directory/index.html [R=301,NC]

#Redirect from old domain to new domain with full path and query string:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC]

#Redirect from old domain with subdirectory to new domain w/o subdirectory including full path and query string:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subdirname/(.*)$
RewriteRule ^(.*) http://www.katcode.com/%1 [R=302,NC]

Rewrite and redirect URLs with query parameters (files placed in root directory)

Original URL:

http://www.example.com/index.php?id=1
Desired destination URL:

http://www.example.com/path-to-new-location/
.htaccess syntax:

RewriteEngine on
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^index\.php$ /path-to-new-location/? [L,R=301]
Redirect URLs with query parameters (files placed in subdirectory)

Original URL:

http://www.example.com/sub-dir/index.php?id=1
Desired destination URL:

http://www.example.com/path-to-new-location/
.htaccess syntax:

RewriteEngine on
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301]
Redirect one clean URL to a new clean URL

Original URL:

http://www.example.com/old-page/
Desired destination URL:
http://www.example.com/new-page/
.htaccess syntax:

RewriteEngine On
RewriteRule ^old-page/?$ $1/new-page$2 [R=301,L]
Rewrite and redirect URLs with query parameter to directory based structure, retaining query string in URL root level

Original URL:

http://www.example.com/index.php?id=100
Desired destination URL:

http://www.example.com/100/
.htaccess syntax:

RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]
Rewrite URLs with query parameter to directory based structure, retaining query string parameter in URL subdirectory

Original URL:
http://www.example.com/index.php?category=fish
Desired destination URL:
http://www.example.com/category/fish/
.htaccess syntax:

RewriteEngine On
RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]
Domain change – redirect all incoming request from old to new domain (retain path)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]
If you do not want to pass the path in the request to the new domain, change the last row to:

RewriteRule ^(.*)$ http://www.example-new.com/ [R=301,L]

#From blog.oldsite.com -> www.somewhere.com/blog/
retains path and query, and eliminates xtra blog path if domain is blog.oldsite.com/blog/
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}/ blog
RewriteRule ^(.*) http://www.somewhere.com/%{REQUEST_URI} [R=302,NC]
RewriteRule ^(.*) http://www.somewhere.com/blog/%{REQUEST_URI} [R=302,NC]

apache_conf 配置示例1

配置示例1

apps_first.json
{
  "apps": {
    "app1": {
      "name": "test_app_1",
      "groups": ["backends"],
      "hosts": ["host1", "host2"]
    },
    "app2": {
      "name": "test_app_2",
      "groups": ["databases", "backends"],
      "hosts": ["host1"]
    }
  },
  "hosts": {
    "host1": {
      "host": "localhost",
      "user": "root",
      "groups": ["main_hosts"]
    },
    "host2": {
      "host": "some_host",
      "user": "some_user_name",
      "groups": ["main_hosts", "some_hosts_group_name"]
    }
  }
}
config_with_apps_in_hosts.json
{
  "hosts": {
    "host1": {
      "host": "localhost",
      "user": "root",
      "groups": ["main_hosts"],
      "apps": {
        "app1": {
          "name": "test_app_1",
          "groups": ["backends"]
        },
        "app2": {
          "name": "test_app_2",
          "groups": ["databases", "backends"]
        }
      }
    },
    "host2": {
      "host": "some_host",
      "user": "some_user_name",
      "groups": ["main_hosts", "some_hosts_group_name"]
    }
  }
}
config_with_separate_apps.json
{
  "hosts": {
    "host1": {
      "host": "localhost",
      "user": "root",
      "groups": ["main_hosts"],
      "apps": ["app1", "app2"]
    },
    "host2": {
      "host": "some_host",
      "user": "some_user_name",
      "groups": ["main_hosts", "some_hosts_group_name"],
      "apps": ["app1"]
    }
  },
  "apps": {
    "app1": {
      "name": "test_app_1",
      "groups": ["backends"]
    },
    "app2": {
      "name": "test_app_2",
      "groups": ["databases", "backends"]
    }
  }
}