.htaccess doesn't work in apache - php

I have the following problem:
I want to remove .php and .html extention from url of my website.
The URL is localhost/MySiteDir/MySitePage.php and I want to obtain localhost/MySiteDir/MySitePage.
I am following this:
https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
& this
How to remove file extension from website address? guides.
So I created a .htaccess file on my MySiteDir and I put this code on this file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
But it doesn't work.
I have changed etc/apache2/sites-enabled/000-default.conf file adding
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
in this way:
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
and in my .htaccess file I put:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
when I try to access my website I receive a 404 Error.

Related

pretty url not working on laravel5.2

It seems that pretty URLs are not working for me. I have tried every thing I know, when you try http://wasamar.com.ng/login it gives a response of 404 Not Found but http://wasamar.com.ng/inde.php/login is ok, I have edited my public/ directory's .htaccess file to this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This is the /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName wasamar.com.ng
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/wasamar/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
What am I doing wrong?
It's probably because your apache rewrite module is not enabled. To enable the rewrite module on a Ubuntu machine:
sudo a2enmod rewrite
sudo service apache2 restart
If a2enmod is not available on your platform, you need to open up your httpd.conf file and uncomment the line including rewrite_module. That's something like this on a macOS machine:
LoadModule rewrite_module libexec/mod_rewrite.so
Then you need to restart the service.
Also, for htaccess files to be effective you need to set AllowOverride directive to All. Here's an example:
<Directory "/absolute/path/to/webserver/root">
# ...
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
# ...
</Directory>
thanks everyone for the support but i saw my error, in the /etc/apache2/apache2.conf file i did not add the AllowOverride All section the dirctory tags, when i fixed that it worked.

laravel 5.2 project not running without adding index.php on url

Hello Everyone I am working on my project which in on Laravel 5.2. I have setup my project on my local machine but its now working without adding index.php in url.
I request with the url :-
http://localhost/project_folder/admin
While I am trying to run without index.php and run my url it gives me following error.
Not Found
The requested URL /project_folder/admin was not found on this server.
For this I did following steps :
1) Give permission (777) to storage and cache folder.
2) I Go to path /etc/apache2/sites-available/000-default.conf and edit it, now it look something like this.
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
In my .htaccess file have following code.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^(.*)/$ /moduleTesting/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Please suggest me if I forget any requirement or anything else.
please enable mode rewrite.
Please ensure that you have mod rewrite enable on your system.(search for mod_rewrite in info.php having code)
<?php
phpinfo();
?>
in terminal run command:
$ sudo a2enmod rewrite

css and js files have 403 forbidden error after activating mod_rewrite

I'm working on an application using Codeigniter Framework .
I wanted to remove the index.php from the url , so I activated the mod_rewrite , and I modified the .htacces files , the index.php has been removed , and the application run perfectly but the css files and and js files dont want to load .
to loads a css file i use this line
<link <?php echo 'href="' . base_url() . 'application/views' . '/css/bootstrap.min.css" rel="stylesheet"' ?>>
but it says
You don't have permission to access /kingplast/application/views/css/bootstrap.min.css on this server.
for more informations i'll provide my 000-default.conf file and the .htacces file
000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
.htacces
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /kingplast/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
and by the way i tried to chmod the files to 777 and it didn't worked .
for more information i'm running Ubuntu 15.04
please help me i'm stacked
Remove this and try again:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>

Apache web server configuration gives 404 error message

Mates,
I've been looking arround but still couldn't find the solution.
I have this on apache2.conf
<Directory /home/pablo/htdocs/elementalguru/cuentas/idpetecuador.com/www/system/public>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This on 000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
# ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /home/pablo/htdocs
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/home/pablo/htdocs/elementalguru/cuentas/idpetecuador.com/www/system/public"
ServerName eguru.idpet.sys
</VirtualHost>
And the .htaccess file on public folder is like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
But still when I try to access a url like
http://eguru.idpet.sys/clinicas
Which is stated in hosts file.
I get a 404 error message.
Any idea why?
Thanks in advance!
Is your mod_rewrite enabled?
Try $ a2enmod rewrite and then restart apache.
Here is the laravel/laravel .htaccess, have you tried this?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Cant resolve url to Index Controller

I've created a simple Zend Framework 1.12 test app via the zf.bat on my windows machine (xampp, php5.3): "zf create project testapp"
After that i've created an new controller called 'FoobarController' next to the 'IndexController'.
Now I can switch between these urls:
localhost/projects/testapp/public/
localhost/projects/testapp/public/index
localhost/projects/testapp/public/foobar
Now I have uploaded the whole testapp into the web server directory of my raspberry pi (192.168.1.100, Apache2, PHP5.3, ModRewite On, AllowOverride All).
This urls are working fine when I call the raspberry from the windows machine:
192.168.1.100/sites/testapp/public
192.168.1.100/sites/testapp/public/foobar
This one will display: "The requested URL /sites/testapp/public/index was not found on this server"
192.168.1.100/sites/testapp/public/index
Has someone an idea why the url to the "index" controller wont work properly on my raspberry? (I did nothing more than the explained steps)
/etc/apache2/sites-available/default:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/var/www/html"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess:
RewriteEngine On
RewriteBase /sites/testapp/public
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

Categories