500 Internal Server Error - htaccess - .htaccess

I get this error :
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator at webmaster#vitrinsaz1.ir to
inform them of the time this error occurred, and the actions you
performed just before this error.
More information about this error may be available in the server error
log.
content of my .htaccess :
AddType application/x-httpd-php53 php53 php
php_flag log_errors on
php_flag display_errors on
#php_value error_reporting 8
php_value error_reporting E_ALL
php_value error_log /domains/vitrinsaz1.ir/public_html/error_log2
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^vitrinsaz1.ir$ [NC]
RewriteRule ^(.*)$ http://www.vitrinsaz1.ir/$1 [R=301,L]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
order allow,deny
allow from all
I think my .htaccess is ok but when I remove the content of my .htaccess every thing become ok.

You have to add AllowOverride All in your default virtualhost config file (default path : /etc/apache2/sites-available/default) or for a specific virtualhost.
By default AllowOverride is set to None

php_flag is not allowed in PHP CGI mode

Related

Apache2 rewrite condition with https

I have 2 .htacces file
/usr/local/apache2/htdocs .htacess file with
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/test2/
RewriteRule ^(.*)$ /test2/$1 [NC,QSA]
/usr/local/apache2/htdocs/test2 .htacess file with
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteRule !^(ui/|index.php|favicon.ico) - [F,L,NC]
#RewriteCond %{HTTPS} off
#RewriteCond %{REQUEST_URI} !^/admin
#RewriteRule .* https://%{HTTP_HOST}%/admin [L,R=301]
</IfModule>
The application will force the application to the url below while hiding the index.php
http://www.example.com/admin
additionally there is another link with http://www.example.com/display
default directory configured in httpd.conf are :
DocumentRoot "/usr/local/apache2/htdocs/test2"
<Directory "/usr/local/apache2/htdocs/test2"
However if I try to run with https the link
https://www.example.com/admin
I will get this error :
Forbidden
You don't have permission to access /admin/ on this server.
I have tried using the #commented code and still has error. Please help
These problem were fix by applying
I have found out that there are another file, ssl.conf that has a DocumentRoot, fix the problem via adding the same document root in ssl.conf
DocumentRoot "/usr/local/apache2/htdocs/test2"
<Directory "/usr/local/apache2/htdocs/test2"
and
Change a file php.conf to (# was the old code)
# Depreciated in Apache 2.2
# Order allow,deny
# Deny from all
# Satisfy All
# New in Apache 2.4
<RequireAll>
Require valid-user Require ip 127.0.0.1
</RequireAll>

How To Remove System Directory Does Not Exist

I Am Trying To Install A Kohana Based Script But I Am Getting A Error See Above In The Image
Error
And I Could Not Find What To Do But I Am Sue it Is Related To .Htaccess
SetEnv KOHANA_ENV development
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Disable directory listing
Options -Indexes
<IfModule mod_rewrite.c>
# 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]
RewriteRule .* index.php [PT]
# Remove trailing slash
# RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
# RewriteRule ^(.+)/$ /$1 [R=301,L]
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.+)/$ $1 [L,R=301]
</IfModule>
<IfModule mod_php5.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
according to script owner they said do step 3
Run the installer
Open .htaccess and make the following changes:
Set the correct RewriteBase
but i do not know what to write and what to edit in it i need a little bit help over it
The error means that the application, modules and system folders are not in the same directory as index.php. If you've moved /renamed them you need to change their location in index.php.
If you deleted/modified something by accident, try download Kohana again, obviously the error has nothing to do with .htaccess.
For more info, read the docs https://kohanaframework.org/3.3/guide/kohana/install

htaccess 301 redirect with GET doesn't work

What I want to achieve is the following:
URL /element.php?dogtag=tdcf_tdcbusiness_ak should redirect to /ajankohtaista
I have the following .htaccess:
RewriteCond %{QUERY_STRING} dogtag=tdcf_tdcbusiness_ak
RewriteRule ^element\.php$ /ajankohtaista/? [L,R=301]
But it doesn't work. Any clue what I am missing ?
EDIT: here is my full .htaccess:
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Follow symbolic links in this directory.
Options +FollowSymLinks
# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php index.html index.htm
# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_environment_initialize() in
# includes/bootstrap.inc for settings that can be changed at runtime.
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
php_flag magic_quotes_sybase off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
</FilesMatch>
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule "(^|/)\." - [F]
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
RewriteCond %{QUERY_STRING} dogtag=tdcf_tdcbusiness_ak
RewriteRule ^element\.php$ /ajankohtaista/? [L,R=301]
# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
I think you don't have element.php file anymore (it does not exist).
Because of that, it is rewritten to index.php regarding on your previous rule.
An easy solution would be to swap your two rules.
This part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
RewriteCond %{QUERY_STRING} dogtag=tdcf_tdcbusiness_ak
RewriteRule ^element\.php$ /ajankohtaista/? [L,R=301]
should be like this
RewriteCond %{QUERY_STRING} dogtag=tdcf_tdcbusiness_ak
RewriteRule ^element\.php$ /ajankohtaista [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

.htaccess redirect from domain.org/sub to sub.domain.org/ not working

I'm trying to get aphdigital.org/GVH/ to redirect to gvh.aphdigital.org, and aphdigital.org/GVH/something/ to gvh.aphdigital.org/something/ but I'm having quite a lot of difficulty. I tried the code from this question, but it's not working. The commented-out code blocks below also show failed attempts at a redirect. What am I doing wrong? I would enable logging if I had access to httpd.conf, but I only have FTP access. I know apache is reading this file, because syntax errors seem to cause 500 errors.
Here's my .htaccess file:
# Remember to enable display_errors on development environments only.
<IfModule mod_php5.c>
php_value display_errors 1
php_flag register_globals off
</IfModule>
RewriteEngine on
# If know that mod_rewrite is enabled, but you are still getting mod_rewrite errors,
# uncomment the line below and replace "/" with your base directory.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/ - [C]
RewriteRule .* admin/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
# Added this on Jan. 4, 2013 to redirect from old URL to new. Doesn't seem to be working.
RewriteCond %{HTTP_HOST} ^www.aphdigital.org/GVH$
RewriteCond %{HTTP_HOST} ^www\.aphdigital\.org/GVH$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [L,QSA,R=301]
# End of Jan. 4 add.
#TEST for redirect added April 3. Also doesn't work.
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC]
#TEST2, code from Stackoverflow question
#Options +FollowSymLinks -MultiViews
#RewriteEngine on
#RewriteBase /
# To redirect http:://www.mysite.co.uk/ to http:://mysite.co.uk/
#RewriteCond %{HTTP_HOST} ^www\.(aphdigital\.org)$ [NC]
#RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC]
#END TEST 2
#Intentionally breaking to see if reading .htaccess. Yep, this breaks it.
#<directory / ></directory>
<FilesMatch "\.(php|ini)$">
Order Allow,Deny
Deny from all
</FilesMatch>
<Files index.php>
Allow from all
</Files>
# Uncomment the lines below in order to enable caching of some files via Apache (after a finished site has gone live)
<IfModule mod_expires.c>
# <FilesMatch "\.(js|ico|gif|jpg|png|css)$">
# ExpiresActive on
# ExpiresDefault "access plus 10 day"
# </FilesMatch>
</IfModule>
This is for a site running the Omeka CMS.
The URL path GVH is not part of %{HTTP_HOST}, so this should be
RewriteCond %{HTTP_HOST} ^(?:www\.)?aphdigital\.org$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [R,L,NC]
Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Removing index.php in CodeIgniter using .htaccess file

I'm currently developing a website using CodeIgniter and I recently stumbled upon a routing & .htaccess problem.
Basically, the structure of my simple website (let's call my project 'CIExample' for the sake of simplicity) is as follow:
-Home
-About Us
-Our Service
-News
-Contact Us
which I implemented using a Page controller. This controller has 5 functions which called respective page's view, i.e:
Home(), which calls the view 'Home'
About(), which calls the view 'About Us' and so on..
Previously, to access 'Home', I would need to type http://localhost/CIExample/index.php/page/home into the url window, but after setting the following routes I was able to remove the 'page' (classname) part:
$route['default_controller'] = 'page/home';
$route['home'] = 'page/home';
$route['about'] = 'page/about';
$route['service'] = 'page/service';
$route['news'] = 'page/news';
$route['contact'] = 'page/contact';
However, the tricky part came when I try to remove the 'index.php'.
I want to be able to access the home page by typing http://localhost/CIExample/home.
So I did a lot of searches on CI forum/tutorial/stack overflow, and found some codes for .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
or http://ellislab.com/forums/viewthread/197675/#929904
I tried both codes but none works..
http://localhost/CIExample/home would direct me to 404 not found page, but http://localhost/CIExample/index.php/home would work just fine.
I wonder what went wrongs? Is it my routes.php or .htaccess or both?
Thanks.
Note: I've also changed my 'config/config.php' file -> $config['index_page'] = '';
EDIT:
Finally it works!
After tweaking the config.php file in config folder and set the following $config['uri_protocol'] = 'PATH_INFO'; (from 'AUTO').
Available Values:
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
Dunno what's the different but according to one of the comments in http://www.jotorres.com/2011/12/removing-index-php-from-url-in-codeigniter/, the same code might/might not work in the production server.
Anyone can explain the reason maybe?
You just need to paste this in your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
and make this alternation to your application/config/config.php file:
$config['index_page'] = '';
I have use following method, it is working perfectly in UBUNTU...!!
First of all verify that you have enabled mod_rewrite (you can verify using phpinfo()) in your index.php file.
IF DISABLED mod_rewrite then RUN:
1. sudo a2enmod rewrite
2. sudo gedit /etc/apache2/sites-available/defaut
just replace "AllowOverride None" to "AllowOverride All" in Tag(<'Directory /var/www/'>)
3. Then please run sudo service apache2 restart
Ok Good...
Now in your root directory of Codeigniter -> Find .htaccess file, if not found then press ctrl+h , still not found then create a file .htaccess
In .htaccess
Paste following code :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ROOT DIRECTORY NAME/
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Ok finally just replace ROOT DIRECTORY NAME
DONT FORGOT TO REMOVE index.php from application/config/config.php file
Make that line like
$config['index_page'] = '';
I use this htaccess for all my CodeIgniter projects. It supports subfolders too.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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>
In your system/application/config/config.php, Change
$config['index_page'] = "index.php";
To
$config['index_page'] = "";
And in your .htaccess,add this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
for Codeigniter 3.1.4
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php5_module>
php_flag asp_tags On
php_flag display_errors On
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 1000
php_value memory_limit 512M
php_value post_max_size 128M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_value upload_max_filesize 128M
php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Live:
#RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Local:
#RewriteRule .* index.php/$0 [PT,L]

Resources