Perplexing .htaccess/PHP Conundrum - php

So... I finished a site on my local server, and I uploaded it to my remote server.
Going to the remote site yields an Internal Server error. I think there might be something wrong with the .htaccess file. Here's what it contains:
Options All -Indexes
Options +FollowSymlinks
DirectoryIndex launcher.php
IndexIgnore */*
RewriteEngine ON
RewriteRule ^(.*)\.less$ $1.css.php [nc]
RewriteRule ^([A-Za-z]+)$ launcher.php?page=$1 [QSA,L]
Eventually, I tried to debug the problem by adding # before the DirectoryIndex line to see what would happen. The result:
403 Forbidden
You don't have permission to access /site/ on this server.
Which is puzzling, because all the permissions seem to be ok... I double checked, the .htaccess file has octal 644.
What could be causing this issue? Thanks for any responses in advance.

Thanks to the help SO users, my problem was solved.
Apparently, Apache freaks out if the .htaccess file has permissions set to write, so I was able to fix the problem by chmoding the entire directory and everything in it to 755.

I had the same problem and as the error message says, the file mentioned was having permission 664. I just removed the write permission for group and the permission became 644. That fixed the error.

Related

wordpress 403 error (duplicator installation)

I have duplicated my site using the duplicator plugin from wordpress.org. However, when I wanted to run this on a new hosting service, first I encountered a 504 gateway timeout error. Therefore, I extracted the .zip contents and chose for manual package extraction, which solved the problem, but after the second step, again in the final step (test), I run into a 403 access denied error.
I checked my access permissions, they were OK. (755 for folders and 644 or 666 for files)
I checked my .htaccess file, it seemed to be OK. (I deleted it and the error appeared again).
There are no plugins on my domain or host which might cause interference as I am installing the package afresh.
I don't know what is causing this problem.
My .htaccess file contents:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
403 Forbidden error code is shown when your server permissions don’t allow access to a specific page.
Another possible cause could be a corrupt .htaccess file or incorrect file permissions on your server.
If you were already using an automatic WordPress backup plugin, then make sure that you have access to the latest backup before moving forward.
Deactivate all WordPress plugins
First thing you need to do is to temporarily deactivate all WordPress
plugins. This includes any security plugins that you may have installed on your site.
If this resolves your problem, then this means one of the plugins on
your website was causing this error.
You can figure out which plugin was causing the error by activating
all your plugins one at a time until you are able to reproduce the
403 forbidden error.
Corrupt .htaccess File
Often the 403 error is caused by a corrupt .htaccess file in your WordPress site. Repairing this file is quite easy.
You need to delete the file from your server. (get backup file)
Try accessing your website. If 403 forbidden error is resolved, then this means that your .htaccess file was corrupt.
You can generate a fresh .htaccess file by logging into your WordPress admin area and going to Settings » Permalinks page.
Simply click on the Save Changes button at the bottom of the page and WordPress will generate a fresh .htaccess file.
File Permissions in WordPress
All folders on your WordPress site should have a file permission of
744 or 755.
All files on your WordPress site should have a file permission of 644
or 640.
You can set the file permission to the root folder to 744 or 755.
Check the box next to ‘Recurse into subdirectories’ and then check
the option that says ‘apply to directories only’.
I hope this helped you fix the 403 forbidden error in WordPress
This is old but I would like to post something I'm about to try. I found that "open_basedir" may be enabled by default on some hosts, like the one I'm using. So I sent a request to the provider to disable it from "php.ini" file.

Why does this Rewrite rule throws a 500 inside .htaccess file?

on a server with PHP and mod_rewrite I have the following .htaccess in the document root:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .(rewriteme)$ rewrite.php [L]
</IfModule>
When I make a request to http://theserver.com/arewriteme, I get a 500 internal server error.
But on my local system, the rule above works great and the script rewrite.php is executed (it simply echoes It works!) when I request http://localhost/arewriteme:
<?php echo "It works!"; ?>
Why do I get a 500 error on the remote server though? I don't have access to the global Apache configuration, but I am sure the module gets loaded as `phpinfo() shows:
I looked at different questions here on SO, but basically all say that it the error is due a syntax error within .htaccess (which is not my case because the rule works on localhost).
So, maybe, there's something in the global configuration of Apache? Maybe the creation of .htaccess is somehow denied? Could it be possible?
Thanks for the attention.
EDIT: I was able to contact the hosting provider and they told me that they disabled .htaccess throught the whole htdocs directory. How did they do that so that the server thrown a 500 Internal Server Error? AllowOverride None inside the main Apache won't do the job because in this case Apache would simply ignore the rules inside the .htaccess but won't throw any error...

uploading yii2 basic on shared hosting but not working

I am installing Yii2 on a shared hosting environment,Apache, (Godaddy),
here is what I did as per the docs:
Renamed web folder to www
copied all the folders, now the directory structure looks like this:
public_html\
assets
commands
config
controllers
model
modules
views
www\index.php
.htaccess (this is both in public_html and www)
but when I access my domain, I get the following error:
You don't have permission to access / on this server. Additionally, a
404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.
Here are the contents of my .htaccess which I have copied in both public_html and www.
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
is the htaccess creating problem? Is index.php not being run from the right folder? What else should I look for? any help is much appreciated.
Update:
The actual problem with the above error was that It was a Permissions issue.
Set the permissions from 644 to 755, and now the system is accessible.
BUT
the to access index.php I still need to navigate to it manually by typing in the url : www.example.com/www/index.php
UPDATE
As I don't have prettyurl's enabled, just to make it work, I deleted all the contents of the .htaccess, then I copied the contents of basic folder in the home folder (for future visitors it should be like home/your_user _name
CAVEAT EMPTOR
I know almost nothing about .htaccess. Also my this project is just for learning, this solution may not be useful in production settings.
Question is still open for expert advice on best practices in such scenario.
You need to move your domain pointer to www instead of htdocs, its probably somewhere under domain -> root folder. Your .htaccess looks fine.

Symfony2 remove web from the url on the external server

I've been looking for the solution for a long time. There are a lot of such topics and I know it. But I still can't figure it out. How can I remove web from the symfony2 project url? I tried to do this with htaccess looking like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]
but it doesn't work. It gives me an error:
No route found for "GET /web/"
I really can't change the root directory on this server as only thing I have is FTP permission. Anybody has any idea for this?
Edit: I also tried a trick to put all the files from web in root directory and the rest of the project higher. The problem is the highest directory I have access to is the root.
You shall need to update your virtual host config file and set the DocumentRoot to point to the web folder.
For example you may currently have it set as
DocumentRoot /var/www/myproject/
but you need to update it to
DocumentRoot /var/www/myproject/web
More information can be found within the Symfony2 cookbook here
Also this shall stop anyone trying to access the config/parameters.yml

File not found with .htaccess file on Apache server

I have this .htaccess on my Windows dev machine and everything works fine
RewriteEngine On
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/webserv/$1 [R=301,L]
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2 [L,NC,QSA]
When I upload it on my Centos server I get the error
404 The requested URL path_to_script/login.php was not found on this server.
I cannot understand why this is. The file is definitely there and I gave permissions 777.
I have checked if the .htaccess is actually used by adding rubbish in it and getting an internal error (500) which means that it is working.
Also when I use .htaccess to make restrictions on IPs that have access to the directory it works. mod_rewrite is loaded as shown in the phpinfo() I have tried.
I am at a loss here.
EDIT
I noticed that it tries to search in the base_path appending it to the root path e.g.
/path_to_script/path_to_script/login.php
And that is why it fails. How do I solve this?
I finally solved it but in a way that I am not sure I like. At least it works. If someone has a better solution I would be glad to see it.
RewriteRule ^login/([0-9]+)/([0-9]+)$ http://host/webserv/login.php?par1=$1&par2=$2
The reason I don't like this solution is because I does not give a pretty url. It just redirects.
I still do not understand why I get the root directory appended to the request if I instead write:
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2

Categories