htaccess的mod-rewrite:链接从根子目录 - 子目录中忽视迪尔斯? [英] htaccess mod-rewrite: link to subdirectory from root - neglect dirs in subdirectory?
问题描述
我问的<一部分href="http://stackoverflow.com/questions/12042347/htaccess-routing-to-subdirectory-on-server-performance-loading-tim">this 的问题,前一阵子的计算器,这完美的作品: ES
I asked part of this question a while ago on stackoverflow and this works perfect: es
我有一个多域服务器的每个目录correspondend到一个域名。但是我的主域名www.mydomain.com也是我的服务器上的目录,而不是链接到自动。
I have a multi-domain-server each directory is correspondend to a domain-name. However my main-domain name www.mydomain.com is also a directory on my server and not linked to automatically.
这就是为什么我用这个在我的网站的根目录...
This is why I use this in my root of the website …
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/my-website/
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -d
RewriteRule ^(.*)$ /my-website/$1 [L]
现在,当我打电话www.my-website.com它自动运行 /我-网站
目录。这只是罚款。然而在此目录中我在它与此另一个.htaccess文件。
Now when I call www.my-website.com it automatically runs the /my-website
directory. That's just fine. However in this directory I have another .htaccess file with this in it.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^/projects/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^/jobs/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^(/downloads/.+)/?$ assets/$1 [L,NC]
因此,这意味着本网站像一些链接/项目/
只是被忽视的,不实际存在。
So this means that for this website some links like /projects/
are just "neglected" and don't actually exist.
但是,如果我运行这个网站现在住在我的根主htaccess的文件在我的服务器,并因,在我的子目录中RewriteConditions不工作,我得到一个未找到
However if I run this website now live on my server and due to the main-htaccess file in my root, the RewriteConditions in my sub-directory don't work and I get a "Not found"
我怎样才能使这项工作起来呢?
How can I make this work together?
推荐答案
有这样说道:
的DocumentRoot / htaccess的:
RewriteEngine On
RewriteBase /
RewriteRule ^projects/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^jobs/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^(downloads/.+)/?$ assets/$1 [L,NC]
# add .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_URI} !^/my-website/
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI} -d
RewriteRule ^(.*)$ /my-website/$1 [L]
/my-website/.htaccess:
RewriteEngine On
RewriteBase /my-website/
# add .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/my-website/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
这篇关于htaccess的mod-rewrite:链接从根子目录 - 子目录中忽视迪尔斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!