.htaccess 如何重定向到具有多个域的主页?
我们公司使用几个URL来访问相同的内容。对于这个问题,我将使用: 我们收到了一些甚至不应该存在的虚假页面请求(例如wp-login.php,我们使用的是Drupal)。为此,我想将它们重定向到我们的主页。我在.htaccess文件中尝试了以下操作,但无效.htaccess 如何重定向到具有多个域的主页?,.htaccess,redirect,.htaccess,Redirect,我们公司使用几个URL来访问相同的内容。对于这个问题,我将使用: 我们收到了一些甚至不应该存在的虚假页面请求(例如wp-login.php,我们使用的是Drupal)。为此,我想将它们重定向到我们的主页。我在.htaccess文件中尝试了以下操作,但无效 Redirect 301 /wp-login.php / 因为我使用了3个不同的URL,所以我不知道该怎么做 我想做的是: 重定向到 重定向到 重定向到 编辑: 这是我的整个htaccess文件: #Redirect files Red
Redirect 301 /wp-login.php /
因为我使用了3个不同的URL,所以我不知道该怎么做
我想做的是:
#Redirect files
Redirect 301 /apple-touch-icon.png /misc/apple-touch-icon.png
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^wp-login.php(.*)? / [R=301]
#AuthName "Restricted Area"
#AuthType Basic
#AuthUserFile /var/www/content/.htpasswd
#AuthGroupFile /dev/null
#require valid-user
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
#compress certain files
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php
# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
# There is no end quote below, for compatibility with Apache 1.3.
ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>
# Set the default handler.
DirectoryIndex index.php
# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.
# PHP 4, Apache 1.
<IfModule mod_php4.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
php_value post_max_size 300M
php_value memory_limit 1000M
php_value upload_max_filesize 300M
php_value max_execution_time 600000000
php_value session.hash_bits_per_character 4
php_value session.save_path "/var/lib/php5"
#php_admin_flag engine on
php_flag xcache.cacher 1
php_flag xcache.optimizer 1
#php_flag eaccelerator.enable 1
#php_flag eaccelerator.optimizer 1
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive on
ExpiresByType image/jpeg A604800
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType audio/mpeg A604800
# Cache all files for 0 weeks after access (A).
# ExpiresDefault "access plus 3 days"
#Caching Removed
ExpiresDefault A1
Header unset Cache-Control
Header append Cache-Control: "no-cache,must-revalidate"
# Do not cache dynamically generated pages.
#ExpiresByType text/html A1
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment and adapt the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
RewriteBase /
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
# $Id: .htaccess,v 1.90.2.3 2008/12/10 20:04:08 goba Exp $
#重定向文件
重定向301/apple-touch-icon.png/misc/apple-touch-icon.png
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写规则^wp login.php(.*)?/[R=301]
#AuthName“限制区”
#AuthType Basic
#AuthUserFile/var/www/content/.htpasswd
#AuthGroupFile/dev/null
#需要有效用户
#
#Apache/PHP/Drupal设置:
#
#保护文件和目录免受窥探。
命令允许,拒绝
#不显示映射到目录的URL的目录列表。
选项-索引
#遵循此目录中的符号链接。
选项+FollowSymLinks
#压缩某些文件
SetOutputFilter放气
#让Drupal处理任何404错误。
ErrorDocument 404/index.php
#对不存在的favicon.ico请求强制发送简单错误消息。
#为了与Apache1.3兼容,下面没有结束语。
ErrorDocument 404“未找到请求的文件favicon.ico。
#设置默认处理程序。
DirectoryIndex.php
#覆盖PHP设置。更多信息,请访问sites/default/settings.PHP
#但在运行时无法更改以下内容。
#PHP4,Apache1。
php\u值魔法\u引号\u gpc 0
php\u值寄存器\u全局0
php_值session.auto_启动0
php_值mbstring.http_输入传递
php_值mbstring.http_输出过程
php_值mbstring.encoding_翻译0
#PHP4,Apache2。
php\u值魔法\u引号\u gpc 0
php\u值寄存器\u全局0
php_值session.auto_启动0
php_值mbstring.http_输入传递
php_值mbstring.http_输出过程
php_值mbstring.encoding_翻译0
#PHP5、Apache1和Apache2。
php\u值魔法\u引号\u gpc 0
php\u值寄存器\u全局0
php_值session.auto_启动0
php_值mbstring.http_输入传递
php_值mbstring.http_输出过程
php_值mbstring.encoding_翻译0
php_值后最大尺寸300M
php_值内存_限制1000M
php\u值上传\u最大\u文件大小300M
php_值最大执行时间600000000
php_value session.hash_bits_per_character 4
php_value session.save_path“/var/lib/php5”
#php_admin_标志引擎打开
php_标志xcache.cacher 1
php_标志xcache.optimizer 1
#php_标志eaccelerator.enable 1
#php_标志eaccelerator.optimizer 1
#需要启用mod_expires。
#启用过期。
过期于
过期按类型图像/jpeg A604800
过期按类型图像/gif A604800
ExpiresByType图像/png A604800
过期按类型应用/x-shockwave-flash A604800
过期按类型音频/mpeg A604800
#访问(A)后,将所有文件缓存0周。
#ExpiresDefault“访问加3天”
#缓存已删除
到期默认值A1
头取消缓存控制
标头追加缓存控制:“无缓存,必须重新验证”
#不要缓存动态生成的页面。
#ExpiresByType文本/html A1
#各种重写规则。
重新启动发动机
#如果您的站点既可以使用“www.”前缀访问,也可以不使用“www.”前缀访问,则您可以
#可以使用以下设置之一将用户重定向到您的首选
#URL,带或不带“www.”前缀。请仅选择一个选项:
#
#要重定向所有用户以访问带有“www.”前缀的网站,
# (http://example.com/... 将被重定向到http://www.example.com/...)
#调整和取消注释以下内容:
RewriteCond%{THE_REQUEST}^.*/index.html
重写规则^(.*)index.html$http://www.example.com/$1[R=301,L]
重写cond%{HTTP_HOST}^example\.com[NC]
重写规则^(.*)http://www.example.com/$1[R=301,L]
#
#要重定向所有用户以访问不带“www.”前缀的站点,
# (http://www.example.com/... 将被重定向到http://example.com/...)
#取消注释并调整以下内容:
#RewriteCond%{HTTP_HOST}^www\.example\.com$[NC]
#重写规则^(.*)$http://example.com/$1[L,R=301]
#如果在子目录或子目录中使用Drupal,请修改RewriteBase
#VirtualDocumentRoot和重写规则无法正常工作。
#例如,如果您的站点位于http://example.com/drupal 取消注释和
#修改以下行:
#重写BASE/drupal
#
#如果您的站点在以下位置的VirtualDocumentRoot中运行:http://example.com/,
#取消对以下行的注释:
重写基/
#将表单“x”的URL重写为表单“index.php?q=x”。
重写cond%{REQUEST_FILENAME}!-f
重写cond%{REQUEST_FILENAME}!-d
RewriteCond%{REQUEST_URI}!=/favicon.ico
重写规则^(.*)$index.php?q=$1[L,QSA]
#$Id:.htaccess,v 1.90.2.3 2008/12/10 20:04:08戈巴经验$
编辑:
更新的htaccess文件
#Redirect files
Redirect 301 /apple-touch-icon.png /misc/apple-touch-icon.png
#AuthName "Restricted Area"
#AuthType Basic
#AuthUserFile /var/www/content/.htpasswd
#AuthGroupFile /dev/null
#require valid-user
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
#compress certain files
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php
# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
# There is no end quote below, for compatibility with Apache 1.3.
ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>
# Set the default handler.
DirectoryIndex index.php
# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.
# PHP 4, Apache 1.
<IfModule mod_php4.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
php_value post_max_size 300M
php_value memory_limit 1000M
php_value upload_max_filesize 300M
php_value max_execution_time 600000000
php_value session.hash_bits_per_character 4
php_value session.save_path "/var/lib/php5"
#php_admin_flag engine on
php_flag xcache.cacher 1
php_flag xcache.optimizer 1
#php_flag eaccelerator.enable 1
#php_flag eaccelerator.optimizer 1
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive on
ExpiresByType image/jpeg A604800
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType audio/mpeg A604800
# Cache all files for 0 weeks after access (A).
# ExpiresDefault "access plus 3 days"
#Caching Removed
ExpiresDefault A1
Header unset Cache-Control
Header append Cache-Control: "no-cache,must-revalidate"
# Do not cache dynamically generated pages.
#ExpiresByType text/html A1
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^wp-login.php(.*)? / [R=301]
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment and adapt the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
RewriteBase /
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
# $Id: .htaccess,v 1.90.2.3 2008/12/10 20:04:08 goba Exp $
#重定向文件
重定向301/apple-touch-icon.png/misc/apple-touch-icon.png
#AuthName“限制区”
#AuthType Basic
#AuthUserFile/var/www/content/.htpasswd
#AuthGroupFile/dev/null
#需要有效用户
#
#Apache/PHP/Drupal设置:
#
#保护文件和目录免受窥探。
命令允许,拒绝
#不显示映射到目录的URL的目录列表。
选项-索引
#遵循此目录中的符号链接。
选项+FollowSymLinks
#压缩某些文件
SetOutputFilter放气
#让Drupal处理任何404错误。
ErrorDocument 404/index.php
#强制执行简单错误消息以重新启动
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^wp-login.php(.*)? / [R=301]
... other rules ...
</IfModule>
RewriteRule (^|/)wp-login\.php(/|$) /? [L,NC,R=302]