2

I've found a few answers but none of them seem to be able to answer my problem. On my server we use non-www for asset serving and www subdomain is cnamed to our bigcartel store. What I'm trying to do is serve files from the non-www page if file is found, else redirect to the www subdomain with original request.

eg: redirect domainname.com/product-name to www.domainname.com/product-name because it doesn't exist on our asset server.

I've tried the following; but I've had no luck.

RewriteEngine On
RewriteBase /

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^domainname\.com [NC]
RewriteRule (.*) http://www.domainname.com/$1 [R=301,L]
4

1 回答 1

0

你的逻辑条件倒退了。当条件说:请求的资源是现有文件、现有符号链接或现有目录时,您似乎正在重定向。你想要相反的:

RewriteEngine On
RewriteBase /

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^domainname\.com [NC]
RewriteRule (.*) http://www.domainname.com/$1 [R=301,L]
于 2013-01-23T18:12:18.897 回答