Jump to content

403 Forbidden on Local Development Environment


Cole
 Share

Recommended Posts

Long time listener, first time caller...

I have been working with ProcessWire for some time now and it has been amazing, my go to CMS. Previously my workflow had a local development setup through MAMP using an address like http://localhost:8888/websites/example.com.

I have recently changed this in preference of  http://dev.example.com, that way I do not need to disable the .htaccess forward from non-www to www to develop locally. My .htaccess forward is setup like:

  RewriteCond %{HTTP_HOST} !^dev\. [NC]
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This works on all sites that are still using ProcessWire 2.5, however on sites using 2.8 and 3.0 I am getting a 403 Forbidden error. After reading through the forum posts related to 403 errors I have not been successful in finding a solution for my issue. Has anyone experienced this or can assist? Thank you very much in advance, the forum community has been so helpful I have never needed to post until now.

Link to comment
Share on other sites

Hi and welcome @Cole.

Could you please provide some more information...

Is the 403 error occurring in your local environment or online?

Are those rewrite rules the source of the error - that is, does the error disappear if you remove those lines from htaccess?

Does the error occur when you access the website via all three of the below?
dev.example.com
www.example.com
example.com

And I take it that you are routing dev.example.com to 127.0.0.1 by editing whatever the MacOS equivalent is to the Windows 'hosts' file and have configured that domain as an Apache virtual host in your local environment?

  • Like 1
Link to comment
Share on other sites

1 hour ago, Robin S said:

Are those rewrite rules the source of the error - that is, does the error disappear if you remove those lines from htaccess?

That is the thing I would check first!

I'm pretty sure that the apache directives in your post can not be responsible for the http 403. Neither in a local environment nor on a live server.

  • Please check other .htaccess files in parent directories or apache config files.
  • Check for redirects in your template files or config.php

 

Link to comment
Share on other sites

Thanks for the replies guys! My notifications didn't come through, my apologies for the delay.

I had commented out all apache directives while testing this, individually, all together, my directives, ProcessWire's directives etc. The 403 seems unrelated. There are not any redirects in the template or config files. I also had added the dev URL to the HTTP Hosts Whitelist in the config file.

Also this only happening on local and not online. I am using MAMP Pro for the local server using ports 80 and 443 with a host of dev.example.com

Is there anything stored in the database that could affect this?

Link to comment
Share on other sites

3 hours ago, Cole said:

Also this only happening on local and not online. I am using MAMP Pro for the local server using ports 80 and 443 with a host of dev.example.com

But are you positive you are actually connecting to the local site when you visit dev.example.com? If you haven't configured your hosts file correctly your browser may be attempting to connect to an online server where that address does not resolve to anything and hence the error. If you put a file "test.txt" in your local site root and visit dev.example.com/test.txt can you see your file?

  • Like 2
Link to comment
Share on other sites

Great catch! My hosts are setup the same as all the other builds that are working, but I just realized the builds that are not working belong to another developer on my team. Initially I thought it was a version issue, but could it be the way it was installed? They also do still use http://localhost:8888/websites/example.com for local development.

And yes the test file is coming up not found.

 

Link to comment
Share on other sites

On 07/03/2017 at 6:54 PM, Cole said:

I have recently changed this in preference of  http://dev.example.com, that way I do not need to disable the .htaccess forward from non-www to www to develop locally.

I don't understand this part. I tried doing this locally ( I use dev.mysite.com like you) with the www enabled and it doesn't work. You end up being redirected to www.dev.mysite.com. I have to leave the www disabled locally, and have it enabled on the live server, same with the https option. Does your local site work without the www?

Link to comment
Share on other sites

7 hours ago, SamC said:

You end up being redirected to www.dev.mysite.com.

To avoid this you need to add the line:

  RewriteCond %{HTTP_HOST} !^dev\. [NC]

So the full directive is:

  RewriteCond %{HTTP_HOST} !^dev\. [NC]
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

First line checks if this is NOT the subdomain 'dev'. The next line checks if it is NOT the subdomain 'www'. Finally, if both conditions are true, redirect to 'www'. So if the subdomain is 'dev' or 'www' this rule is ignored, saving you from commenting it out all the time. That is why I wanted to stop using http://localhost:8888/websites/example.com, because you have to comment that rule out for local.

Be sure to clear your cache after adding that line to the www directive in your htaccess file. This works on all of my builds. My assumption now as to why I am getting the 403 with the builds from my team members is that they used a prepackaged version of ProcessWire for use with Foundation. I use the ProcessWire install that is provided by ProcessWire.

If I get any new information about my 403 issue, I will reply with what I discover.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...