嗨虽然这个问题被多次询问但是我的问题有点不同,我尝试了很多但却无法完成它。
我有一个在wordpress中运行的网站说“http://example.com”和另一个网站“/ jobs”文件夹(一个简单的核心php网站)。现在我的问题是当用户登陆“http://www.example.com/jobs”及其内部链接时,使用我们的jquery的重定向不起作用,因为对于重定向,我们使用URL作为没有'www'的基本URL。
现在我怎么可能使用htaccess将我的网站从www切换到非www只用于文件夹及其所有内部文件夹。
我们Root网站的Htaccess:
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<ifModule mod_headers.c>
Header unset Pragma
FileETag None
Header unset ETag
<FilesMatch ".(js|css)$">
Header set Cache-Control "max-age=29030400, private"
</FilesMatch>
<FilesMatch "\.(jpg|jpeg|png|gif|swf|ico)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</ifModule>
<ifModule mod_deflate.c>
<filesmatch "\.(js|css|html|swf|xml)$">
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</filesmatch>
</ifModule>
我们/ jobs文件夹的Htaccess:
suPHP_ConfigPath /home1/project_name/public_html/jobs
<Files php.ini>order allow,deny
deny from all
</Files>
RewriteEngine On
Options -Indexes
RewriteRule ^search/(.*) /jobs/?location[]=$1&q=$2&bookMark=$3&scrollFlag=$4&countScroll=$5&sort=$6 [L]
RewriteRule ^companies/(.*)/(.*)/(.*)$ /jobs/joblisting.php?comp_id=$1&jobRole=$2&pgno=$3 [L]
RewriteRule ^companies/(.*)/(.*)$ /jobs/joblisting.php?comp_id=$1&pgno=$2 [L]
RewriteRule ^companies/(.*)$ /jobs/joblisting.php?comp_id=$1 [L]
<ifModule mod_headers.c>
Header unset Pragma
FileETag None
Header unset ETag
<FilesMatch ".(js|css)$">
#set max-age for 1 YEAR
#Header set Cache-Control "max-age=29030400, private"
#set max-age for NEVER CACHE
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</FilesMatch>
<FilesMatch "\.(jpg|jpeg|png|gif|swf|ico)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</ifModule>
# log PHP errors to a file
# File modified on Tue Feb 25 22:07:48 2014 by server
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
# php_flag log_errors on
# File modified on Tue Feb 25 22:07:52 2014 by server
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
# php_value error_log "/php_errors.log"
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
答案 0 :(得分:0)
只需匹配主.htaccess中的jobs文件夹即可使用www。
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/jobs
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
或如果你想要一行。
RewriteRule ^jobs/(.*)$ http://example.com/jobs/$1 [L,R=301]