我有一个多域设置,看起来像这样在我的服务器上…这是一个模型的结构:
1.)根.htaccess文件应该确保我的主域是/my-website
在进入www.my-website.com
时自动运行/执行。 由于我有一个多域ftp服务器,我需要指定的事实。 那已经在工作了。
2.)在我的子目录/my-website
我需要一些不同的规则,特别是关于更好的urldevise和.php扩展名的省略。
/my-website
我想忽略所有.php
后缀。 /jobs
/projects
这样的目录,这些目录实际上不是目录,而是自己的php文件。 这是我迄今为止感谢@anubhava在这个线程 。
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]
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]
但是,现在使用这个时,我的问题,在my-website
链接没有尾随.php
不会工作。 我想我的链接工作像/projects
但运行/ exectute /projects.php
在我的网站。 然而,目前这不起作用,我得到了404。我也想/projects/some-project
运行/执行/some-project.php
(其中projects
目录实际上并不存在)哪些不起作用也是404。
/my-website
我希望所有的链接工作,没有尾随。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]
RewriteEngine On RewriteBase /my-website/ # add .php extension RewriteCond %{DOCUMENT_ROOT}/my-website/$1\.php -f [NC] RewriteRule ^(?:[^/]+/)?([^/]+)/?$ $1.php [L]
的DocumentRoot /的.htaccess:
RewriteBase / RewriteRule ^projects/(.+?\.php)$ /$1 [L,NC] RewriteRule ^jobs/(.+?\.php)$ /$1 [L,NC] RewriteRule ^(downloads/.+)/?$ assets/$1 [L,NC] # add .php extension for REQUEST_FILENAME existing in / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC] RewriteRule ^(.+?)/?$ $1.php [L] # Check if REQUEST_URI is existing as file or directory in /my-website 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] # Check if REQUEST_URI is existing as file.php in /my-website RewriteCond %{REQUEST_URI} !^/my-website/ RewriteCond %{DOCUMENT_ROOT}/my-website%{REQUEST_URI}.php -f RewriteRule ^(.*)$ /my-website/$1 [L]
/my-website/.htaccess:
RewriteEngine On RewriteBase /my-website/ # To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+?)/?$ $1.php [L]