0

I have a WordPress installed in /var/www/wordpress/ and my own code in /var/www/project/

Now comes the following problem: When I try to access example.com/client/ or example.com/admin/ it should link to /var/www/project/ and execute the .htaccess + index.php from there.

I have tried to place an Alias directive in the Apache config with partial success.

Alias /admin/ /var/www/project
Alias /client/ /var/www/project

When I access example.com/client/ it works fine, but as soon as I request example.com/client/login it failes with File does not exist: /var/www/project/login error.

The .htaccess in /var/www/project looks like

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ index.php?module=$1&task=$2 [L,QSA]
Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47
Aley
  • 199
  • 2
  • 3
  • 16

2 Answers2

2

First of all: my pet peeve, quoted from from the manual on .htaccess files:

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

Second: the canonical answer to almost all mod_rewrite questions is here

I'm not 100% sure, but I think that by setting the RewriteBase to / the internal redirect as you have it will be to example.com/index.php and not to /var/www/project/index.php. Additionally I think the PT flag is required to take into account the Alias matching.

You may want to try

Alias /admin/ /var/www/project
Alias /client/ /var/www/project
<Directory /var/www/project>
  RewriteEngine On
  RewriteBase /
  # Do nothing when a file or directory with the requested name exists
  RewriteCond %{REQUEST_FILENAME} -f  [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.* - [L]

  # Use the request URL to select the correct module and task
  RewriteRule ^/([^/]+)/(.*)$ /$1/index.php?module=$1&task=$2 [PT,L,QSA]
</Directory>
HBruijn
  • 72,524
  • 21
  • 127
  • 192
0

The documentation for Alias shows that this is the expected behavior. Alias appends any trailing paths after the aliased path.

I think what you want is to throw away the additional path information in the alias, by

AliasMatch /(admin|client)/.* /var/www/project

That should send the request to /var/www/project, while leaving the URL path of the original request intact for processing by the RewriteRule.

Andrew Schulman
  • 8,561
  • 21
  • 31
  • 47