codiad in subdir results in error 500 - .htaccess

i've installed codiad in a subdir of a webserver (xyz.com/codiad). the root dir .htaccess file is as follows:
Options -Indexes
AddDefaultCharset utf-8
AddCharset utf-8 .js
AddCharset utf-8 .php
AddCharset utf-8 .md
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule (.+)\.htm$ index.php
RewriteRule (.+)\.md$ index.php
RewriteRule (.+)\.txt$ index.php
ErrorDocument 404 /404.htm
trying to do the inital setup of codiad results in an internal server error 500 of the process
.../codid/components/install/process.php
and i assume codiad needs its own .htaccess file ..
i have to say that i have no access to the apache config files, only FTP to the webspace
generally, how can i override the .htaccess file of any parent directory ?

Related

Config .htaccess

It's my first time deploying a web app on a hosting and they give me this .htaccess but i've never configured one, i have a root directory then a public_html and at the same level my webpage. i'll show you the directory tree and the content of the .htaccess
root
|
|---project
|---public_html
|---.htaccess
The content of the .htaccess is:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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]
</IfModule>
And when I enter the website it's showing me a http 403 error: Server or website configuration is blocking you from viewing this page.
I have never configured a website on a hosting so I don't know what i'm doing most of the time...
Thx!!
root
|
|---project
|---public_html
|---.htaccess
Assuming public_html is the document root (where your public facing files and index.php are located) then the .htaccess file should be in the public_html directory itself (not above it).
That is...
root
|
|---project
|---public_html
|------.htaccess
By placing the .htaccess file in the root directory (above the document root) then it would attempt to rewrite the request to /root/index.php (as opposed to /root/public_html/index.php) which is inaccessible (from rewriting in .htaccess) and does not exist anyway, so would likely result in a 403, 400, etc.

File not found error even if file is present in FTP

I have files present in FTP but when I'm trying to access those files (html files) I'm getting "The requested URL was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."
My .htaccess file code is this and I have tried some of the solutions but none worked. Can you please tell me what's wrong or missing in htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /demosite/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /demosite/index.php [L]
</IfModule>
# END WordPress

2 codeigniter applications & htaccess

I had a codeigniter proyect working in windows with XAMPP and now I was moving it to my RaspberryPi:
Apache/2.2.22 (Debian)
PHP 5.4.4-14+deb7u5
mysql Ver 14.14 Distrib 5.5.31
I have two codeignitir aplications (principal and panel) with this estructure
/ -> (apache root folder)
/appname/admin
/admin/application/ -> (codeigniter application to panel)
/appname/application/ -> (codeigniter application to public)
Now I can't access to admin controllers and I think is because .htaccess. I get this in some url:
my.domain/appname -> codeigniter welcome for public (this part is empty so I think is OK)
my.domain/appname/admin/login.html -> Not Found. The requested URL /mydomain/admin/login was not found on this server.
my.domain/appname/admin/index.php?controller=admin -> 404 Page Not Found (codeigniter style)
my.domain/appname/admin/hello.html -> hello (a dummy file I put to try, works ok)
In my codeigniter panel proyect I have
$config['base_url'] = 'http://my.domain/myapp/admin/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '.html';
I think it's all about .htaccess but I don't understand them. How many files I need? What folders?
I had this .htaccess in my /appname & /appname/panel before
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /appname #to panel /appname/panel
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
I think RewriteEngine on is activated in my apache2.
I found solution by .htaccess inside admin's folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /appname/admin
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'appname' to your applications folder name.
RewriteCond %{REQUEST_URI} ^appname.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
CodeIgniter multiple applications htaccess
<IfModule authz_core_module>
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

.htaccess redirect & hide directory path in url

I have wordpress installed in root directory. I want to use some separate php files as a page on my domain, for which I have made a separate directory which holds all files for serving the php files, of which the directory structure is as:
the root folder has all the wordpress files
the directory which I'd like to serve as a page
/inc/css/
/inc/php/
/inc/img/
the CSS stylesheet files directory location in the PHP file is ../inc/css one step back & then css folder.
I want to hide folders from URL such as the files are served from the root (hide the /inc/php/, /inc/css/ & /inc/img/ folders from URL).
eg: www.domain.com/inc/php/about.php redirect & rewrite this URL to www.domain.com/about
the .htaccess in my root
RewriteEngine On
RewriteBase /
# disable directory browsing
Options -Indexes
# Prevent hotlinking of images htaccesstools.com/hotlink-protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [NC,F,L]
RewriteRule ^login$ http://domain.com/wp-login.php [NC,L]
# 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
<files wp-config.php>
order allow,deny
deny from all
</files>
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
I have tried the simple redirect rule but the folders are exposed in the URL.
Redirect 301 /about.php /inc/php/about.php
also I have some more files in the PHP folder on which I'd like to apply the same rule of redirect & rewrite URL & hide folders from URL & remove the PHP extention.
www.domain.com/inc/php/about.php redirect & rewrite this URL to www.domain.com/about
This, of course, means that you can't have the same base filename that's a php file and, say, a css file. Since if the request is www.domain.com/about, is that supposed to map to /inc/php/about.php or /inc/css/about.css? Or is it an image? If you have both files, only one will get mapped to.
But if that's really what you want, try adding these rules right after the hotlinking rule that you have:
# Externally redirect requests for /inc/
RewriteCond %{THE_REQUEST} \ /inc/(php|img|css)/([^\?\ ]+)\.(php|css|jpe?g|png|gif) [NC]
RewriteRule ^ /%2 [L,R=301]
# Check if the request is a php file:
RewriteCond %{DOCUMENT_ROOT}/inc/php%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ /inc/php/$1.php [L]
# Check if the request is a css file:
RewriteCond %{DOCUMENT_ROOT}/inc/css%{REQUEST_URI}.css -f
RewriteRule ^(.*)$ /inc/css/$1.css [L]
# Check if the request is a jpeg file:
RewriteCond %{DOCUMENT_ROOT}/inc/img%{REQUEST_URI}.jpg -f
RewriteRule ^(.*)$ /inc/img/$1.jpg [L]
# Check if the request is a gif file:
RewriteCond %{DOCUMENT_ROOT}/inc/img%{REQUEST_URI}.gif -f
RewriteRule ^(.*)$ /inc/img/$1.gif [L]
# Check if the request is a png file:
RewriteCond %{DOCUMENT_ROOT}/inc/img%{REQUEST_URI}.png -f
RewriteRule ^(.*)$ /inc/img/$1.png [L]

mod_rewrite, can't rewrite existing file

I'm trying to pass all images in a directory to watermark.php using mod_rewrite in .htaccess.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.jpg$ /watermark.php?path=%{REQUEST_FILENAME} [L]
It works fine on local machine, but on my online production server (shared hosting) all image files are served without rewriting.
mod_rewrite is enabled online, but it ignores the rule if file exists.
What could be wrong?
UPDATE
Here's my full setup: there's a domain with a subdomain in a subfolder of main domain's document_root.
public_html (example.com DOCUMENT_ROOT)/
img (img.example.com DOCUMENT_ROOT)/
.htaccess in public_html folder:
<FilesMatch "\.(inc\.php|log)$">
Deny from all
</FilesMatch>
Options -Indexes +FollowSymLinks
php_value short_open_tag 0
php_value auto_prepend_file /home/username/public_html/bootstrap.inc.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^img\. [NC]
RewriteRule .* - [L]
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\. [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ shop/$1 [L]
.htaccess in img folder:
<FilesMatch "\.(inc|log)$">
Deny from all
</FilesMatch>
Options -Indexes +FollowSymLinks
php_value short_open_tag 0
php_value auto_prepend_file none
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.jpg$ /watermark.php?path=%{REQUEST_FILENAME} [L]
The problem is that existing images in img folder are not rewrited. Apache just serve them as is. But if, for example, I request non-existing file the rule works and echo $_GET['path'] prints the full filepath to non-existing file.
Here's what you can use:
RewriteEngine On
RewriteRule ^(media|image|images)(/?)(.*)$ - [F]
RewriteRule ^([a-z0-9\-_\.]+)\.(jpg|jpeg|png|gif)$ /watermark.php?path=%{REQUEST_URI} [L]
The first RewriteRule is set to make sure people don't go to that folder - it gives a 403 permission denied (this is optional)
The second one will redirect any images that match letters, numbers, dash, underscore and dot with the extension: jpg, jpeg, png and gif to your watermark.php file. eg:
http://www.domain.com/logo.jpg => path = /logo.jpg
UPDATE:
Since the rule is in a different folder and the root directory of IMG is /home/username/public_html/img/ the watermark.php file does not exists. Either copy the file you need (watermark.php and its libraries) to the IMG folder or create symblink.
cd /home/username/public_html/img/
ln -s ../watermark.php (and other library files as well)
htaccess change :
Options -Indexes +FollowSymLinks
by
Options -Indexes +FollowSymLinks -MultiViews
This behaviour steel exists on Apache 2.4..

Resources