【发布时间】:2011-10-31 19:02:21
【问题描述】:
我目前为我们的网站安装了 WordPress - 我正在尝试为我们的网站做一个简单的 php 重定向,以便将传入的移动浏览器重定向到我们的移动网站...但是,当我将脚本放入时,没有任何反应,没有重定向,网站只是正常运行。
现在我们有 3 个其他 WordPress 安装(作为同一服务器上的虚拟主机),我可以让重定向在所有其他安装上工作,只是不是我们希望它工作的那个(当然),唯一明显的区别是 htaccess 文件。我不是 htaccess 大师,所以我唯一的想法是 htaccess 文件中的某些内容阻止了我的 PHP 重定向,这可能吗?
或者还有其他我遗漏的可能性吗?
RewriteEngine On
# BEGIN W3 Total Cache
<IfModule mod_setenvif.c>
SetEnvIfNoCase Accept-Encoding (gzip|deflate) APPEND_EXT=.$1
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp- (app|cron|login|register).php|wp-.*\.php|index\.php) [OR]
RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC]
RewriteCond %{HTTP_USER_AGENT} !(bot|ia_archive|slurp|crawl|spider) [NC]
RewriteCond /var/www/wordpress/wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} -f
RewriteRule (.*) wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} [L]
</IfModule>
# END W3 Total Cache
# Performance Options
Header unset Pragma
FileETag None
Header unset ETag
# 1 YEAR
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 18 Apr 2011 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
# 2 HOURS
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
# CACHED FOREVER
# MOD_REWRITE TO RENAME EVERY CHANGE
<FilesMatch "\.(js|css)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2019 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x- javascript
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !.*.(?:gif|jpg|png|pdf|mp3|avi|mpeg|bmp|mov|ico)
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all
</files>
# protect wpconfig.php
<files wp-config.php>
order allow,deny
deny from all
</files>
# Error Document
ErrorDocument 403 /error/403/index.html
# deny directory listings
Options -Indexes
【问题讨论】:
-
发布您的
.htaccess文件怎么样,或者我们应该只是猜测您在做什么?什么类型的重定向,为什么会失败? -
您在谈论 .htaccess 文件中的哪些差异? (请给我们看)。你是怎么做 php 重定向的?...也许 htaccess 可以做到,是的,因为 apache 处理你的请求的方式是在寻找某个 php 文件并处理它之前。
-
有可能。我的意思是,您可以在其中输入
deny from all或php_flag engine off。发布有问题的 htaccess 文件以及您添加到 wordpress 的代码,将大大有助于使您的问题得到解答。 -
你检查过网络服务器日志吗?
-
我编辑了我的帖子,对不起,我没有放 htaccess 文件是我的错。 htaccess 文件是由我们的服务器人员完成的。该脚本即时使用移动浏览器检测脚本,该脚本为我执行标头(位置)重定向。
标签: php wordpress .htaccess redirect