Cole

403 Forbidden on Local Development Environment

9 posts in this topic

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?

1 person likes this

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?

2 people like this

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.

1 person likes this

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 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
    • By sanjom
      Hey, I've used ProcessWire for a while now but not made an appearance in the forum yet  I just wanted to share the solution to a small problem I came across with Let's Encrypt (free SSL service).
      Let's Encrypt SSL certificates need to be renewed every few months to remain active. My web host does this automatically but needs access to a folder named ".well-known", which ProcessWire blocks by default because it starts with a dot. This results in a 403 error.
      To work around this, just add the following line to your .htaccess file, around line 150:
      RewriteCond %{REQUEST_URI} !^(/\.well-known) It should be the first condition in the section titled "Access Restrictions: Keep web users out of dirs that begin with a period".
      I also ran into another problem. Let's Encrypt accesses mail.example.com which is redirected to www.mail.example.com because I enabled the redirection in my .htaccess fie. So we need to exclude the mail sub domain from that rule using the following line as the second condition in the www-redirection section (around line 160):
      RewriteCond %{HTTP_HOST} !^mail\. [NC] I know it's quite a specific problem but maybe it'll help someone Googling the issue.
      I was curious, is there any way of redirecting to the www-version without having to exclude all your sub domains? The only way I can think of involves explicitly writing out your domain name in the .htaccess file and redirecting whenever the %{HTTP_HOST} starts with that name. But obviously that would lead to a loss of generality.
    • By holmescreek
      Summary: If I have a site sitting on a server called testing.com, then on the server change it to mycompany.com, do I have to modify any settings in ProcessWire?
      After building several processwire for clients, the one question that I haven't had is about moving a processwire site from an old (temporary) domain to a new domain.
      For instance, I typically setup development sites for clients and register a temporary domain (and lock with a password). For instance, thee client can go test.com and get all their content finalized, change wording, add news, swap out photos -- everything to make the site production read.  
      Next, on my hosting account I can have testing.com renamed to theircompany.com - and change the nameservers.
      A simple question here. If I have a hosting company rename the account from testing.com to theircompany.com, change my nameservers whereas going to theircompany.com loads the production site, Is there anything I need to change in the processwire configuration or in the PW database?
      In the past, I've just manually copied the site, and fresh-installed PW, and imported the data. Seems like a lot of hassle.
      I have a second part question about updating the PW core, however, after consideration I'll post it as a new topic.
    • By hollyvalero
      I have a website on a shared server that I use to store a few sites. My active domain is at the top.  The new website domain hasn't been activated yet, but the path would be something like:  myactivedomain.com/newdomain.com/ and once the DNS is flipped, just newdomain.com/
      As I am building and adding a load of PDFs, all the links default to /newdomain.com/site/assets/files/etc...
      This isn't migration, but a DNS activation.  Once that is updated, I'm still going to have a bunch of /newdomain.com/ links in there to pages, pdfs, images, etc. 
      Before I resign myself to grepping out page-by-page all the "/newdomain.com/" references I thought I would see if there's a way to update these automatically in processwire but I'm seeing stuff on migration... stuff in the rich editors about correcting links, but I don't see anything that covers this.  Is there a way to do this automatically? Via module? I didn't see anything in the config file... but would be grateful to anyone who can shed some light...