htaccess的在多域设置:其他领域不工作 [英] htaccess on multidomain setup: other domains don't work
问题描述
我有一个多域的设置,看起来像这样我的服务器上......这是结构模型:
I have a multidomain setup that looks like this on my server … this is a model of the structure:
- 的.htaccess
- 我的-网站
- 的.htaccess
- 的index.php
- projects.php
- jobs.php
- 在一些-project.php
- 在另一-project.php
- 在一些-job.php
- 在另一-job.php
- .htaccess
- my-website
- .htaccess
- index.php
- projects.php
- jobs.php
- some-project.php
- another-project.php
- some-job.php
- another-job.php
1)根.htaccess文件应该只是确保,我的主域名是 /我-网站
运行/在进入时自动执行 www.my-website.com
。由于我有一个多领域的FTP服务器,我需要做指定的事实。这是工作了。
1.) The root .htaccess file should just make sure, that my main-domain which is /my-website
is run/executed automatically when entering www.my-website.com
. Due to the fact that I have a multidomain ftp-server I need do specify that. That is working already.
2。)在我子目录 /我-网站
我需要一些不同的规则,特别是关于更好的URL设计的omittance PHP扩展。
2.) In my sub-directory /my-website
I need some different rules, especially regarding better url design and the omittance of .php extension.
- 因此,在
/我-网站
我想忽略所有的.php
后缀。 - 我要像
/作业假目录
/项目
这实际上不是目录,但PHP的文件本身。
- So in
/my-website
I want to neglect all.php
suffixes. - And I want to "fake" directories like
/jobs
/projects
which are actually not directories but php-files themselves.
这是我至今感谢@anubhava在此<一个href="http://stackoverflow.com/questions/27607911/htaccess-mod-rewrite-link-to-subdirectory-from-root-neglect-dirs-in-subdirect">thread.
This is what I have so far thanks to @anubhava in this thread.
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]
不过,我有问题,现在当用这个,我-网站
无拖尾的链接的.php
不会工作。我想我的链接工作像 /项目
但是在我-网站运行/ exectute /projects.php
。然而,这并没有在目前的工作,我得到一个404。
我也想 /项目/部分项目
来运行/执行 /some-project.php
(其中项目
目录实际上并不存在),这也不起作用,还404。
However I have the problem now when using this, that in my-website
the links without a trailing .php
wont work. I want my links to work like /projects
but run/exectute /projects.php
in my-website. However this doesn't work at the moment, i get a 404.
I also want /projects/some-project
to run/execute /some-project.php
(where the projects
directory doesn't actually exist) which doesn't work either, also 404.
- 在我所有的领域现在的工作!所以,我的多领域,设置是保存和handeld。
- 但是里面的
/我-网站
我想各个环节没有结尾.php然后用这个伪造工作目录
- All my domains work now! So my multidomain-setup is save and handeld.
- However inside
/my-website
I want all links to work without trailing .php and with this "faked" directories
所以,现在这个工程...
So right now this works …
- www.my-website.com //作品的
- www.other-domain.com //作品的
- www.my-website.com/projects //不无尾工作的.php 的
- www.my-website.com/projects.php //作品(运行projects.php)的
- www.my-website.com/projects/some-project //不能正常工作(应该运行一些-project.php)的
- www.my-website.com/projects/some-project.php //作品(运行一些-project.php)的
- www.my-website.com // works
- www.other-domain.com // works
- www.my-website.com/projects // doesn't work without trailing .php
- www.my-website.com/projects.php // works (runs projects.php)
- www.my-website.com/projects/some-project // doesn't work (should run some-project.php)
- www.my-website.com/projects/some-project.php // works (runs some-project.php)
推荐答案
有这样的根的.htaccess:
RewriteEngine On
RewriteBase /
## COMMENT out these 2 rules
# RewriteRule ^projects/(.+?\.php)$ /$1 [L,NC]
# RewriteRule ^jobs/(.+?\.php)$ /$1 [L,NC]
RewriteRule ^(downloads/.+)/?$ assets/$1 [L,NC]
# add .php extension
RewriteCond %{DOCUMENT_ROOT}/my-website/$1\.php -f [NC]
RewriteRule ^(?:[^/]+/)?([^/]+)/?$ my-website/$1.php [L]
RewriteCond %{HTTP_HOST} ^(www\.)?my-website\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/my-website/ [NC]
RewriteRule ^(.*)$ my-website/$1 [L]
# add .php extension 2
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(?:[^/]+/)?([^/]+)/?$ $1.php [L]
/my-website/.htaccess:
RewriteEngine On
RewriteBase /my-website/
# add .php extension
RewriteCond %{DOCUMENT_ROOT}/my-website/$1\.php -f [NC]
RewriteRule ^(?:[^/]+/)?([^/]+)/?$ $1.php [L]
这篇关于htaccess的在多域设置:其他领域不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!