.htaccess RewriteEngine On Access Forbidden Error - apache

I got htaccess file, I want to use "RewriteEngine On" but It gives me Access Forbidden error. when I change httpd.conf in AllowOverride All nothing change, it gives same error (Access Forbidden). How can I configure it.
this is code in my httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
This is my htaccess code
RewriteEngine On
RewriteRule ^([^/]*)\.html$ :91/Orginal/SpecialPages.php?PageName=$1 [L]

RewriteEngine On
RewriteBase /Orginal
RewriteRule ^([^/]*)\.html$ :91/Orginal/SpecialPages.php?PageName=$1 [L]

Related

.htaccess file on the localhost

I am trying rewrite my url by .htaccess file. I tried to find out solution before I ask but nothing to seem work. Could you please help out? Thank you.
Here is my .htaccess file (In the root folders):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
RewriteRule ^film/([^/]*)/([^/]*)\.html$ /html/movie/film.php?film=$1&genreID=$2 [L,QSA]
</IfModule>
I did set these lines (in etc/apache2/sites-available/ 000-default.conf):
DocumentRoot /var/www
<Directory "/var/www/html/movie">
AllowOverride All
</Directory>
I am using Linux mate Apache 2.4.7 and in error.log is nothing wrong.
Do you allow mod_rewrite in php.ini?
You have an .htaccess in the document root folder, which is /var/www according to 000-default.conf.
But you don't allow .htaccess files in /var/www. You allow .htaccess files in /var/www/html/movie, again according to 000-default.conf.
To allow .htaccess files in /var/www or /var/www/html, you must say so, e.g.
<Directory /var/www>
AllowOverride All
</Directory>
or
<Directory /var/www/html>
AllowOverride All
</Directory>
N.B. you don't need AllowOverride All, AllowOverride FileInfo is sufficient for using mod_rewrite, see AllowOverride

Enable .htaccess file in OS-X Mavericks

I have my website code at /Library/WebServer/Documents/edu and I'm using the following .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
which I've put under /Library/WebServer/Documents/edu, but apache server seems to be ignoring this file and whatever changes I'm doing here are not taking effect.
Do I need to do some additional changes ?
By default Apache has .htaccess disabled, so you would have to enable it.
Go to and edit /etc/apache2/httpd.conf
You will find a section that looks like this:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
You have to change AllowOverride None to AllowOverride All and then find the section right after which should start with: <Directory "/Library/WebServer/Documents"> and you'll have to change the same thing there to AllowOverride All
The answer is obsolete post Apache 2.4
The right way is:
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
AllowOverride all
Allow from all
</Directory>

Turning RewriteEngine on creates 403 error--how to turn on FollowSymLinks?

I am working with the built-in Apache2 on OSX. I moved the document root to a folder on my desktop and made sure that _www and everyone have read access. It works fine and great, PHP works, everything works until I add a .htaccess with this line only:
RewriteEngine on
As soon as I do that, everything in the directory with the file is 403 Forbidden:
Forbidden
You don't have permission to access /dir/file.txt on this server.
Apache logs show this error:
[error] [client 127.0.0.1] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /Users/uname/Desktop/localhost/dir/filename.txt
I've gone through httpd.conf and made sure that I've enabled FollowSymLinks to no avail:
DocumentRoot "/Users/uname/Desktop/localhost"
<Directory />
Options FollowSymLinks
Options SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/Users/uname/Desktop/localhost">
Options FollowSymLinks
Options SymLinksIfOwnerMatch
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
If I comment out RewriteEngine on in the .htaccess file, then everything works fine, except rewrite rules, obviously. On OSX 10.8.5, httpd.conf is located in /etc/apache2 which also has the folder users containing individual files for uses, e.g. uname.conf, but I've added symlinks in here same as in the other. I noticed there's also a folder extra with files like httpd-userdir.conf, but they don't seem to disable anything.
Where else can FollowSymLinks be turned on (or off)?
You have to either put your Options on one line, or add a + sign in front of your Options so Apache understands you want merge them. At the moment only the last Options directive ('Options Indexes MultiViews') is being applied since it is overwriting all the prior Options.
Try this (which will overwrite the '/' Options):
<Directory "/Users/uname/Desktop/localhost">
Options Indexes MultiViews FollowSymLinks SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I had an issue with getting a 403 the solution for me was changing my rewrite rules. My complete directives are as follows:
<Directory "/var/www/">
<LimitExcept GET POST HEAD>
Order Allow,Deny
Deny from all
Satisfy all
</LimitExcept>
Require all granted
AllowOverride None
# Disable includes and cgi
Options -Includes
Options -ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirdect to HTTPS
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^(.*)$ - [F,L]
# Put your installation directory here:
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# remove index.php
RewriteRule ^(.*)$ /index.php/$1 [L]
# If your host requires forcing query strings.
# Notice the question at the end of index.php
# on the last rule
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
</Directory>
ServerName www.example.com
ServerAlias www.example.com

Will apache RewriteRule overridden by definition in different .htaccess file?

I mean totally different .htaccess file in different directories like c:\dir1.htaccess and c:\dir2.htacesss.
Basically I defined several virtual host in httpd using Alias like below:
Alias /cake "E:\Project\Php\framework\cakephp-cakephp-6864406"
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
Alias /code "E:\Project\Php\framework\CodeIgniter_2.1.0"
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
And each directory has a .htaccess file with below rules:
RewriteBase /cake
RewriteEngine on
RewriteRule (.*) index.php/$1 [L]
and
RewriteBase /code
RewriteEngine on
RewriteRule (.*) index.php/$1 [L]
but if I access http://localhost/code/anything, the request is always captured by cake project.
Am I using it incorrectly? Many thanks!

apache configuration

I'm not good at English.
I use Ubuntu10.04(ja).
I installed pukiwiki(wiki) in /var/www/mypukiwiki. I want to access this page like "http://XX.XX.XX.XX" and redirect "http://XX.XX.XX.XX/pukiwiki" and "http://XX.XX.XX.XX/pukiwiki/" to "http://XX.XX.XX.XX". So, I modified my default configuration file below.
DocumentRoot /var/www/mypukiwiki
RewriteEngine on
RewriteRule /pukiwiki/(.*) /$1 [R]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mypukiwiki>
Options Indexes FollowSymLinks MultiViews
#AllowOverride None
AllowOverride All
Order allow,deny
allow from all
</Directory>
But, Apache redirect only "http://XX.XX.XX.XX/pukiwiki/" to "http://XX.XX.XX.XX".
Apache cannot redirect "http://XX.XX.XX.XX/pukiwiki/" to "http://XX.XX.XX.XX".
Why? I want to know correct configuration.
Would you help me?
Change:
RewriteRule /pukiwiki/(.*) /$1 [R]
to:
RewriteRule ^/pukiwiki/?(.*) /$1 [R,L]
The ^ in the beginning of the match is to ensure you're matching from the beginning of the path, and not match against something like "/foo/bar/pukiwiki", the ? after the slash indicates that it's optional.