Codeigniter4 htaccess file wont work with options all - indexes - .htaccess

i want to setup a new codeigniter4 project.
I've upload all files into www.mydomain.com/sub1/sub2
The htaccess files into www.mydomain.com/sub1/sub2/public makes some trouble.
If i use the default file, i always get a "500 Internal Error"
So i check line by line. so i figure out that the line "Options All -Indexes" produce this error. If i delete it, i see the welcome page. But i think there is a reason why i should add this and related to this "Options +FollowSymlinks" too.
What can caused this problem. In my codeigniter3 projects i use
"DirectoryIndex index.php
Options -Indexes"
and it works fine. Codeigniter4 seems to need it into another way.

After hours of testing and trieing, i find a way (but i not really understand why).
Changing the htacess file in the public folder
from
Options All -Indexes
Options +FollowSymlinks
to this
Options -Indexes
Options SymLinksIfOwnerMatch
solved the problem and the codeigniter project is viewable. So maybe it could help someone.

Related

Why does this RewriteRule work for all extensions but .php?

This simple RewriteRule that I am using for practicing with .htaccess files works almost always:
RewriteEngine on
RewriteRule ^.*$ test.html
When I have the file flowers.html and I use http://localhost/flowers I get redirected to test.html, however when I rename flowers.html to flowers.php I get a 404 page with the message The requested URL /flowers was not found on this server. Does anyone know what causes this?
EDIT:
When I create an empty file called flowers it does redirect properly to test.html. What is going on here?
This does sound like a conflict with MultiViews, so try adding the following at the top of your .htaccess file to disable MultiViews:
Options -MultiViews
MultiViews is not enabled by default, so maybe this has been enabled in your server config?
When MultiViews (part of mod_negotiation) is enabled, a request for /flowers (no extension) will result in Apache searching for an appropriate file to return (based on mime-type) by trying various file extensions of files found in that directory. This is achieved with an internal subrequest before mod_rewrite runs.
However, it's not clear why this would be a problem in your case if you have no other directives? Since your directive simply rewrites everything to test.html (which should include any subrequests). (I was unable to reproduce this behaviour on my Apache 2.4 test server - hence my initial doubt.)

htaccess index files issue - html5boilerplate

I'm using html5boilerplate .htaccess file on one of my projects and i'm having some problems trying to make it works properly.
The main problem is that on sub-directories the index.hmtl file won't load automatically if you type in the address bar its main directory path.
If you try to access to http://provaeur.altervista.org/sitovino/en/wines/ you can see an example. In the directory "wines" there is actually an index.html file but instead of the index you can see a 403 error :(
I've tried to comment these lines:
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
but it seems not to be the solution.
Here you can find a .txt copy of my .htaccess file:
http://provaeur.altervista.org/sitovino/htaccess.txt
Thanks for helping an italian noob :)

How to change base_url in drupal 7, fail to find answer online

I am trying to change base_url on my drupal 7 website, but failed to do it and google a lot, still could not solve it .
I am running localhost/drupal "on my local server. but I want to run it like
" localhost ". ( sorry I have to get rid of http://, otherwise it doesnot let me post)
How to get rid of folder in the url. I know I need to change $base_url on sites/default/setting.php to
$base_url = 'localhost'; // NO trailing slash! ( sorry I have to get rid of http://, otherwise it doesnot let me post)
And in the .htaccess file I am so confused what should I change. People online have their own solution, some said they work , some could not . Could someone give me some suggesttion ?
I assume this has to do with where you have placed your files.
In your file system, remove the 'drupal' directory and place all the files within that at /var/www/html ... instead of /var/www/html/drupal, if that's how it is currently set up.
I feel your pain; I've had this trouble myself before and I believe I had to alter both the settings.php and the htaccess (but try one at a time to begin with). I'm fairly sure that the section below in your .htaccess is what needs changing (just remove the hash from in front of the RewriteBase line). If you're unsure of what you're doing, make a copy of your .htaccess as htaccess.txt and then you can always switch back over if things get nasty.
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
I just realised that what you need is a re-write rule in an .htaccess file within your root folder (not the one that's inside the drupal folder). First, undo any edits you've already made, then create an .htaccess file in the same folder that contains your drupal folder and in it, add:
RewriteEngine On
RewriteRule ^$ /drupal [L]
That should send any traffic from the root into the drupal file structure. If you get issues with strange css, or urls that include the /drupal path, you'll need to revisit the other options in the /drupal/.htaccess file and your settings.php file in order to get it all working correctly.
However, going down this route, you may as well just copy all the files and folders into the root directory anyway (as the first answer suggested), assuming you're not going to be running multiple sites. If you do want to be testing multiple sites, you can just change the RewriteRul above to whatever site directory you're wanting to test in future.

my .htaccess is giving me a Forbidden error

I have the following in the root directory of my site:
RewriteEngine on
RewriteRule ^([^./]{3}[^.]*)$ /index.php?page=$1 [QSA,L]
The .htaccess should be redirecting any request 3 chars or longer without . in the string to the index.php/$string-text as to query my CMS db for output, however when i try and load the index page I get a 403 forbidden error... My .htaccess knowledge is quite basic so try and be easy with me! :)
Thanks
Ric
There does not appear to be anything unexpected with your .htaccess file. If the mod rewrite was not configured correctly, I would expect to see 404 errors or the user being redirected incorrectly. As this does not appear to be the case; you need to widen your search to check that there are no security settings out of place.
I cannot see anything obvious in the httpd.conf file, but here are some of the steps you might want to take.
Remove the .htaccess file - if the website loads okay - then this file is causing an issue somehow; if it doesn't then there is something else wrong.
Check permissions on the web directory being used; there may be a permissions problem.
Check the httpd error log for suggestions.
Ask the question over at serverfault.com or poweruser stack exchange sites.
Ok! So I found the issue, The apache error_log file explained I needed to add this into my .htaccess file and the httpd.conf file -> "Options +FollowSymLinks +SymLinksIfOwnerMatch" and it worked! Now to create my VHost and I am good to go!!! Thanks!!!!!
Thanks
Ric

htaccess rewrite resulting in 500 Internal Server Error

I am trying to get pretty urls using htaccess for SLIR image resizing plugin.
I want to rewrite something like below:
Before Rewrite:
localhost/img/600x400/slider/image.jpg
After Rewrite
localhost/application/public/slir/index.php?r=slir&w=600&h=400&i=img/slider/image.jpg
But the following code is returning a 500 Internal server error...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/([0-9]{1,4})x([0-9]{1,4})/(.*)\.(gif|jpg|jpeg|png) application/public/slir/index.php?r=slir&w=$2&h=$3&i=$1/$4.$5 [NC,NE,QSA,L]
</IfModule>
Please help me.....
UPDATE
I thought it was a File Permissions issue...
so I checked all the related directories and files, surprisingly there were all 755/644.
Then I directly checked the /application/public/slir/index.php. It was not accessible.
I created another file named hello.php in the same slir directory and hello.php was accessible.
Then I moved the SLIR directory to the another folder named public. Here, both the index.php and hello.php were accessible.
After that, I moved SLIR directory to back to the original scripts folder. In scripts folder, hello.php is accessible but index.php is not accessible.
Now, Both files have same permissions and are in same folder.. I dont know what is happening here... :/ :/
Someone please help me......
In case anyone else is looking at this - the problem I found was these two lines in the htaccess file:
php_value auto_prepend_file none
&
php_value auto_append_file none
some servers don't allow them.
moving them to my php.ini file solved it for me:
auto-prepend-file = none
auto-append-file = none
That is probably because you are editing the .htaccess file with a Windows based editor like notepad. Notepad adds some characters to the file which you can't see, but they mess with the .htaccess. I recommend using an editor like Notepad++ and setting the mode to Unix, so it won't mess with the server..
Speaking technically that is because Linux and Windows have different type of EOL ( End Of Line ) so that notepad adds some characters to the end of every line to go to the next line, but Unix won't recognize them, because it has it's own type of EOL..
Slashes are normally forbidden in query strings, but you can enable them by setting
AllowEncodedSlashes directive.
You may also want your rewrite rule to use percent encoding for slashes (that is %2F) so after rewrite:
localhost/application/public/slir/index.php?r=slir&w=600&h=400&i=img%2Fslider%2Fimage.jpg
See also How do you configure apache php to accept slashes in query strings
Duplicate, phrased very differently:
Has anyone used Smart Image Resizer on subdomain sites?
The problem is the subdomain...

Resources