Directing all root traffic to sub folder results in "403 Forbidden" error if you do not have "index.php"

Asked

Viewed 494 times

6

The code below works perfectly to direct all website traffic transparently into the folder www:

Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /

# Verificar o destino
RewriteCond %{HTTP_HOST} ^(www.)?example.com$

# Ignorar se estamos a apontar para a pasta do projeto
RewriteCond %{REQUEST_URI} !^/www/

# Ignorar se estamos a apontar para um ficheiro ou diretoria existente
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Direcionar tudo para a sub-pasta "www"
RewriteRule ^(.*)$ /www/$1 [L] [R=301,L]

The problem is in direct access via ww.example.com that despite serving the page in conditions, results in a HTTP Status code 403 forbidden which causes the failure of some services, including social shares.

However, if we access via ww.example.com/index.php the HTTP status code is correctly identified as 200 OK.

Question

How to solve the problem of access to www.example.com so that they continue to direct traffic, but result in HTTP status code 200 OK ?


Note: Web-site browsing is performed with simplified type Urls:

www.example.com/produtos/bananas/banana-da-madeira
  • Ever tried to use Options +FollowSymLinks?

  • Or put RewriteRule ^(.*)[\\|\/]$ /www/$1/index.php [L] [R=301,L] before your RewriteRule, I guess it is not identifying the default document in the destination folder.

2 answers

1

By using the flag (flare) R=301 the rewrite force the redirect, which I understand you don’t want to redirect, but just rewrite the URL, if that’s the case, you nay must use this flag, just use:

RewriteRule ^(.*)$ /www/$1 [L]

I suppose the briefcase www be a folder create by you and not the apache use folder, for example, if it were a linux system your folder would be something like /var/etc/www/www, if so then your code seems to me correct, except for the flag R.

In case I always use the flare QSA next to the L, in case you want to pass parameter GET together (for example if it comes from a Google ad /?gclid=...), would look something like:

RewriteRule ^(.*)$ /www/$1 [L,QSA]

Details: http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_r

0

I believe I’ve tried, but you’ve put it this way:

# Direcionar tudo para a sub-pasta "www"
RewriteRule ^(.*)$ /www/index.php$1 [L] [R=301,L]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.