Htaccess for multi-domain configuration: other domains do not work

I have a multi-domain setup that looks like this on my server ... this is a structure model:

  • .htaccess
  • *** my site
    • .htaccess
    • index.php
    • projects.php
    • jobs.php
    • some-project.php
    • other-project.php
    • some-job.php
    • other-job.php ***
  • another domain
  • another domain
  • another domain

I have two goals:

1.) . The root .htaccess file should only make sure that my main domain, which /my-websitestarts / runs automatically as you type www.my-website.com. Due to the fact that I have a multi-domain ftp server, I need to specify this. This is already working.

2.) In my subdirectory, /my-websiteI need a few different rules, especially regarding the best URL design and the .php extension extension.

  • , /my-website .php.
  • "" , /jobs /projects, , php .

, @anubhava .

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]

, my-website .php . , /projects, run/exectute /projects.php -. , 404. , /projects/some-project / /some-project.php ( projects ), , 404.

, .

  • ! , - handeld.
  • /my-website , .php ""

, ...

  • 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// ( some-project.php)
  • www.my-website.com/projects/some-project.php// ( some-project.php)
+4
2

root.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]
+2

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]
0

Source: https://habr.com/ru/post/1568719/


All Articles