Index.php rewrite fails after Apache 2.2 to 2.4 update - php

My .htaccess file for a Kohana 3.3 project is:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
Following Eric's advice I have updated the htaccess to the following:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files ".*">
Require all denied
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$0 [PT]
I updated the Virtual Host to include:
<Directory /srv/www/example.com/public_html/>
Require all granted
</Directory>
Did I miss something else?

Modified htaccess
# Protect hidden files from being viewed
<Files .*>
Require all granted
</Files>
and added AllowOverride All to virtualhost config.
<Directory /var/www/example.com/public_html/>
Require all granted
AllowOverride All
</Directory>

Related

PHP script images are missing after migration and changing directory

I have installed my PHP script in a directory of my website psc.af/photo after migration to another domain and in its main directory (public_html in cPanel) everything works fine but the images are not showing up. When i inspect the image link it shows mynewdomain.com/photo/images which is not and it got the photo directory from my previous installation in sub directory. So i cant see the images.
I have tried to change my app url and its fine, the only issue is missing images.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:cDd2jFWmOeQajBVf+UbCcCW9v0OxeZC/w+mp8qwgw0g=
APP_DEBUG=true
APP_URL=http://psc.af/
This is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
Options -Indexes
<Files .htaccess>
order allow,deny
deny from all
</Files>
<Files composer.json>
order allow,deny
deny from all
</Files>
<Files composer.lock>
order allow,deny
deny from all
</Files>
<Files .env>
order allow,deny
deny from all
</Files>
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Remove index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
</IfModule>

.htaccess deny access to file

I wrote the follow .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>
<Files "indexbig.php">
Order Allow,Deny
Deny from all
Allow from 127.0.0.1
</Files>
I want to deny access to the file "indexbig.php" but only allow acces from the local server. Somehow this allows access to every host. Could anyone help me out?

I modified my htaccess file but not sure if it's correct

I wanted to add the "www" infront of my domain, which I have done but not sure if it was added properly because I removed some of the code from the original .htaccess file which came with the open source script.
Original .htaccess file:
# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# disable directory browsing
Options All -Indexes
# disabel access to logs/template files
<Files ~ "\.(log|tpl)$">
order allow,deny
deny from all
</files>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/uploaded [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif)$ [NC]
RewriteRule .* - [F,L]
Current .htaccess file:
# secures htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# disable directory browsing
Options All -Indexes
# disable access to logs/template files
<Files ~ "\.(log|tpl)$">
order allow,deny
deny from all
</files>
# Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^websitename.com$ [NC]
RewriteRule ^(.*)$ http://www.websitename.com/$1 [L,R=301,NC]
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/uploaded [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif)$ [NC]
RewriteRule .* - [F,L]

How to rewrite frontend url in yii2

I am trying to remove frontend from my url address. My url address is before rewriting localhost/abc/frontend/home/index.php and want localhost/abc/ I tried to do this by using .htaccess and I did but when I use htaccess it render me index.php for all menus.. my menus are store in
views
|
|--home|
|--menus
My file structure is like this ..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/$1 [L]
</IfModule>
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
Above codes are of .htaccess of root folder and
its htaccess file stored in home folder
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
#AddType application/x-httpd-php54 .php

htaccess rewriterule not working in codeigniter

Here I am trying to remove index.php from URL in my codeigniter application.
For that, i write .htaccess file like this:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
# RewriteBase /projectname/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php [PT]
It is working in xx.xx.xx.xxx server and mydomain.com. Here i tried to make a same copy to another server yy.yy.yy.yyy. In this, rewrite URL is not working. If i use 'yy.yy.yy.yyy/index.php/login', its working correctly. But 'yy.yy.yy.yyy/login', it throws me 'The requested URL /projectname/login was not found on this server.' error.
For your main directory .htaccess try this and then remove index.php from config.php
Options +FollowSymLinks
Options -Indexes
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Do not touch the .htaccess files in applications directory's.

Categories