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 kixe
      Today I have been running in mysql errors using @renobird s Module MarkupActivityLog which still uses mysqli Driver.
      @all developers
      Although mysqli is still supported PDO driver is the default database driver in PW since https://processwire.com/about/news/introducing-processwire-2.4/
      and its strongly recommend to all module authors to use/change-to PDO driver instead of mysqli.

      @renobird I have sent a pull request.
      A list of other affected modules not updated until now.
      (I try to keep them up to date. Please help)
      @apeisa ProcessTrashman, ProcessRedirects
      @netcarver ProcessDiagnostics
       
    • By danielsl
      latest development version tryed adding url_link field (URL) unfortunately experience this error
       
      Session: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'expo_ch.field_url_link' doesn't exist trued recover db and add field again, every time same result
      any ideas how to create url link and add it to a repeater
      ui Session: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'expo_ch.field_url_link' doesn't exist
      SQLSTATE[42S02]: Base table or view not found
      SQLSTATE[42S02]: Base table or view not found
    • By Dennis Spohr
      Hi all,
      this is my first post here - so let me say first: I love ProcessWire! 
      I have the following scenario:
      On my website users will be able to create their own site. This site is a page (in this case 'theirsite'): "www.mydomain.com/theirsite"
      Now I want that they can use their own domain. So this domain needs to load their page:
      "www.theirdomain.com" goes to "www.mydomain.com/theirsite" but while showing the first domain in the browser.
      I'm trying to archive this with an htaccess entry:
      RewriteCond %{HTTP_HOST} www\.retuschierenlernen\.de RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?it=retuschierenlernen/$1 [L,QSA] I get the following error, because it loads the my main site, not the page of my user:
      Warning: file_put_contents(/www/mysite/test/html/site/assets/cache/FileCompiler/site/templates/public-site.php): failed to open stream: Permission denied in /www/mysite/test/html/wire/core/FileCompiler.php on line 327 Thanks!
      Dennis
    • By fryk
      Hallo,
      I use Processwire for a few months now. And I was really happy with it. Now, I have a problem that might be related to Processwire - or not. I hope someone can give me a hint.
      My problem is this: Accessing my Processwire website is really slow on a ("local") XAMPP installation. Frontend as well as backend.
      The situation: I used Processwire 3.0.42 / XAMPP for Windows 5.6.28-1 on my local PC to make a website. All worked fine. Then I moved my htdocs and mysql Database to a NAS (changed the mysql.ini / httpd.conf files), so my co-worker could access the files, too. From that point, processwire takes about 5 seconds, until a page starts to load. With plain HTML/PHP websites this problem doesn't seem to occur. I made a new Processwire Installation, but that did not change anything.
      mysql shows no errors. Apache shows a few notices and warnings, mostly:
      AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
      AH00354: Child: Starting 150 worker threads.
      Does anyone have the same problem, an idea what I could try to do, or even better, a solution? I really wonder why that is ... 
      Thanks a lot!