Cole

403 Forbidden on Local Development Environment

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.

Share this post


Link to post
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

Share this post


Link to post
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

 

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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.

 

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@Cole that's really useful, thanks for the tip. I'll try that out, one less difference between the local & live .htaccess to worry about.

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Peter Knight
      I have a single Processwire install with two domains pointing to it.
      There's
      in-progress.com which is the "proper domain" and won't be live for a few months mini-project.com which needs to go live immediately but just point to a sub-page Is there a way with .htaccess to know when the site is being accessed through mini-project.com, keep that address is the browser bar and redirect to mini-project.com/project-home/
      To give a little context, a part of the in-progress needs to be accessible immediately and we've registered that temporary mini-project.com and pointed it at the same site.
      The key here is to only do that redirect when mini-project.com is the source request. Otherwise I guess I'd use Jumplinks etc
       
       
    • By Barry
      I'm trying to direct all pages from their www and http versions to their non www https versions but I'm experiencing some really strange redirecting behaviour instead.
      When I uncomment the http to https lines in the htaccess, I get a too many redirects error on my site I thought that Processwire by default redirected from www to non www? When I apply the following line after the Processwire directives
      RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] The redirecting seems to work fine but for some reason many of the pages redirect to the homepage.
      I don't know if its a factor but I have jumplinks and multi-language installed and running.
      I've removed all custom rules from the htaccess just so that people see the pages they click on from search engines, but I'm hoping this can be resolves quick. Ideas?
    • By mr-fan
      Like title says i've some domains with umlauts öäüß and i'd like to redirect them to the non umlaut version
      example:
      http://my-domän.de to http://my-domaein.de
      i've somethings like this in my htacess:
      ##redirect umlautdomain (not my domain) RewriteCond %{HTTP_HOST} ^xn--mhldorf-nsb.d$ [NC] RewriteRule ^(.*)$ http://muehldorf.de//$1 [R=301,L] in my config.php i only have muehldorf.de in my hosts list...
      is there something that i've misunderstood? so far it doesn't work....but may the htaccess rules take some time to exicute...i tried since about an hour some different rules.
      regards mr-fan
    • By alan
      I've been using clamp http://jide.github.io/clamp/ for a while now, rather than installing MAMP or MAMP PRO.
      Like MAMP, it delivers Apache, MySQL (via MariaDB), and PHP.
      Unlike MAMP it runs from the command line (the 'c' in clamp).
      Also unlike MAMP, all settings and data (database), sit alongside the website files in a .clamp folder (you need to add this to .gitignore to stop dev environment leaking into production).
      Apart from being free, it's just brilliant to use.
      If you get errors or stuck, check the logs, the docs are brief but excellent.
      Enjoy!
    • By fabjeck
      Hi all. Some days ago I migrated my website from local (xampp) to online. Everything works fine exept one thing. When i try to fill a field of the type "url" (with an external link) i get an 403 - forbidden message. Writting text in textfields , body etc. works. Now I don't know if the problem comes from processwire or the server itself...
      Did anybody have the same/similar troubles?
      Thanks for helping!
      cheers