Elemenofi
Elemenofi

Reputation: 374

How to configure .htaccess in XAMPP for windows?

I cant make this .htaccess work on XAMP 3.2.1 for Windows. It does work on my boss's MAMPRO for Mac and in our client's Apache for Linux.

I get this error:

Access forbidden!

You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

If you think this is a server error, please contact the webmaster.

Error 403

www.rapsodia.loc
Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9

Here is the complete file

RewriteEngine On

RewriteCond %{HTTP_HOST} .*\.ar/?$
RewriteRule ^(.*)$ http://www.rapsodia.loc/ar/$1 [R=301,L]

RewriteCond %{HTTP_HOST} .*\.cl/?$
RewriteRule ^(.*)$ http://www.rapsodia.loc/cl/$1 [R=301,L]

RewriteCond %{HTTP_HOST} .*\.uy/?$
RewriteRule ^(.*)$ http://www.rapsodia.loc/uy/$1 [R=301,L]

RewriteCond %{HTTP_HOST} .*\.br/?$
RewriteRule ^(.*)$ http://www.rapsodia.loc/br/$1 [R=301,L]

RewriteCond %{HTTP_HOST} .*\.mx/?$
RewriteRule ^(.*)$ http://www.rapsodia.loc/mx/$1 [R=301,L]

RewriteCond %{HTTP_HOST} .*\.co/?$
RewriteRule ^(.*)$ http://www.rapsodia.loc/co/$1 [R=301,L]

RewriteCond %{HTTP_HOST} .*\.ve/?$
RewriteRule ^(.*)$ http://www.rapsodia.loc/ve/$1 [R=301,L]

#####Si no es .com. a /ar#####
RewriteCond %{HTTP_HOST} !^rapsodia.loc.$ [NC]
RewriteRule ^$ http://www.rapsodia.loc/ar/$1 [R=301,L]
##############################

RewriteCond %{REQUEST_URI} ^/(uy|ar|cl|ve|mx|co|br)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

RewriteCond %{THE_REQUEST} ^GET\ /ar/ [OR] %{THE_REQUEST} ^POST\ /ar/
RewriteRule ^ar/(.*)$ %{DOCUMENT_ROOT}/v15/$1 [L]

RewriteCond %{THE_REQUEST} ^GET\ /uy/ [OR] %{THE_REQUEST} ^POST\ /uy/
RewriteRule ^uy/(.*)$ %{DOCUMENT_ROOT}/v15/$1 [L]

RewriteCond %{THE_REQUEST} ^GET\ /cl/ [OR] %{THE_REQUEST} ^POST\ /cl/
RewriteRule ^cl/(.*)$ %{DOCUMENT_ROOT}/v15/$1 [L]

RewriteCond %{THE_REQUEST} ^GET\ /br/ [OR] %{THE_REQUEST} ^POST\ /br/
RewriteRule ^br/(.*)$ %{DOCUMENT_ROOT}/v15/$1 [L]

I can confirm my Windows's host file and XAMPP's httpvhosts files are properly configured because my other virtual hosts are working just fine.

We did several tests and apparently this is what is not working: RewriteRule ^ar/(.*)$ %{DOCUMENT_ROOT}/v15/$1 [L] . The problem originates in the fact that we have to rewrite say for example www.rapsodia.local.ar to www.rapsodia.local/ar/ in order for our website to work properly. Apparently Apache tries to find the /ar/ directory inside the route of the vhost and when it does not find it (because it is just a url rewrite), it throws an error.

Any help would be immensely appreaciated.

Upvotes: 1

Views: 2194

Answers (1)

Elemenofi
Elemenofi

Reputation: 374

I changed these rules

RewriteRule ^ar/(.*)$ %{DOCUMENT_ROOT}/v15/$1 [L]

to

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

and now it works just fine. For some reason %{DOCUMENT_ROOT} was the source of my problem.

Thanks!!!

Upvotes: 1

Related Questions