Apache 在WAMP中为本地开发配置多个域

Step 1
======

In the file: C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
Find: NameVirtualHost *:80     Replace with: NameVirtualHost *

In the file: C:\wamp\bin\apache\Apache2.2.11\conf\httpd . conf
Find: #Include conf/extra/httpd-vhosts.conf     and delete the #

Step 2
======
Location: C:\Windows\System32\drivers\etc\hosts

For Each Website you will need to insert the following: 127.0.0.1 www.domain.dev

127.0.0.1 represents the IP for your localhost.


Step 3
======
Location: C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf

For Each Website add the following:

<VirtualHost *>
	ServerName www.domain.dev
	DocumentRoot "C:/wamp/www/domain.com/"
</VirtualHost>

Remove those 2 dummy virtual hosts and add:

<VirtualHost *:80>
	ServerName localhost
	DocumentRoot C:/wamp/www/
</VirtualHost>

Also add this if you want others on the network to access your local machine:

<VirtualHost *:80>
	ServerName 192.168.1.??
	DocumentRoot C:/wamp/www/
</VirtualHost>

Apache HTACCESS - 定义404

ErrorDocument 404 /404.html

Apache 通过.htaccess在WordPress中利用浏览器缓存

## EXPIRES CACHING ##

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 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 2 days"

## EXPIRES CACHING ##

Apache 更高效的Wordpress RewriteRule

# BEGIN WordPress
RewriteEngine on
#
# Unless you have set a different RewriteBase preceding this
# point, you may delete or comment-out the following
# RewriteBase directive:
RewriteBase /
#
# if this request is for "/" or has already been rewritten to WP
RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L]
#
# END wordpress

Apache 使用htaccess重定向域

RewriteCond %{HTTP_HOST} ^(www\.)?socdetio\.com [NC]
RewriteRule ^(.*)$ http://www.socdetio.cat/$1 [R=301,L]

Apache 从htaccess设置PHP值

#php_value max_execution_time 900
php_value max_input_time 3600
php_value upload_max_filesize 64M
php_value post_max_size 128M

Apache http basic auth

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /path/to/htpasswd/file
Require valid-user

Apache 301重定向查询字符串

RewriteCond %{QUERY_STRING} ^querystring$
RewriteRule ^index\.php$ http://www.domain.com/page.html? [R=301,L]

//EXAMPLE


RewriteCond %{QUERY_STRING} ^url=page1$
RewriteRule ^content\.php$ http://www.domain.com/index.html? [R=301,L]

Apache Ubuntu apache vhost_alias设置

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        ServerName example.com
        ServerAlias *.example.com
        VirtualDocumentRoot /home/%1/www/html
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Apache .htaccess,指向子目录的根目录

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteCond %{REQUEST_URI} !subdir/
RewriteRule (.*) /subdir/$1 [L]