0

Hello i have the following page:

1st site folder: www.site.com /www/www1/
2nd site folder: www2.site.com /www/www2/
Ajax Folder: /www/ajax/
CDN Folder: /www/cdn/

the www and www2 site uses some ajax stuff, since i dont want to create a own ajax folder to each site, i want to use the same directory, what i want to do is the following:

I have my www and www2 sites, each one must use the same ajax folder, im trying to create a virtual folder to each one that connects to my ajax folder.

So must be www.site.com/ajax/myfileajax.php?id=1 Also for www2.site.com/ajax/myfileajax.php?id=2

Im trying with .htaccess but no luck only a 404 error

RewriteRule /inc/^(.*) ../ajax/$1 [L]

I don't want to recode all my javascript for x-domain ajax that's why i want to do this. My hosting provider can't edit the httpd.conf so this is my only chance with .htaccess. I tried alias too but don't work.

4

1 回答 1

0

尝试将其放在文档根目录中的 htaccess 文件中适当的位置(我假设是 /www/):

RewriteEngine On

# for www.site.com
RewriteCond %{HTTP_HOST} www.site.com [NC]

# check that the request needs to be routed (ajax/cdn don't need to be routed)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# check that we get routed to an existing file or directory
RewriteCond %{DOCUMENT_ROOT}/www1%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/www1%{REQUEST_URI} -d 

# Do the route to /www1/
RewriteRule !^/?www1 /www1%{REQUEST_URI} [L]


# for www2.site.com
RewriteCond %{HTTP_HOST} www2.site.com [NC]

# check that the request needs to be routed (ajax/cdn don't need to be routed)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# check that we get routed to an existing file or directory
RewriteCond %{DOCUMENT_ROOT}/www2%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/www2%{REQUEST_URI} -d 

# Do the route to /www2/
RewriteRule !^/?www2 /www2%{REQUEST_URI} [L]

第一项检查是确定请求所针对的主机名。第二个检查是请求不是针对现有资源的。如果请求是 for/ajax/myfileajax.php我们不需要做任何路由如果该文件存在于 /ajax/ 目录中。第三项检查是确保如果我们路由,我们会将 URI 指向现有资源。这个位只是为了让 404 错误报告请求的 URI,而不是/www1/前面附加的 URI。换句话说,除非那里有东西,否则不要路由,否则让它像平常一样只是 404。

于 2012-08-02T21:09:45.970 回答