RewriteEngine not allowed here - apache

Some time ago I made a .htaccess file and it worked:
RewriteEngine On
RewriteBase /MVC
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Now I installed it on another machine and I get the Apache error:
/home/zalmoksis/www/public/MVC-demo/.htaccess: RewriteEngine not allowed here
What may be wrong?
Some relevant Apache configuration around (if you need something more, just say so):
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/zalmoksis/www/public
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /home/zalmoksis/www/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
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
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
and this:
Alias /MVC /home/zalmoksis/www/public/MVC-demo
<Directory /home/zalmoksis/www/public/MVC>
Options FollowSymlinks
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
</IfModule>
</Directory>

Just a thought. Are you sure mod_rewrite.so isn't disabled in httpd.conf?

Related

cannot access url string something missing on my code?

I have a problem with apache giving me a "not found" error.
scenario:
I have a url of the form --> 10.17.10.19/webapps/api/index.php?url=auth
I want to rewrite the url in the form --> 10.17.10.19/webapps/api/auth
im Using Ubuntu 20.04 apache2
vhost:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
htaccess:
RewriteEngine On
Options All -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
apache.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes
# FollowSymLinks
# AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
Please help me to correct the condition to recognize the parameter
i found the answer
i need to enable header so the htaccess can work
ae2enmod header
https://httpd.apache.org/docs/2.4/mod/

Sub-domain not working

I'm pretty new to apache, so probably the solution will be obvious to you... I'm running on Debian wheezy
Here are my two file in /etc/apache2/sites-availables:
amelineandraphael
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName amelineandraphael.raphaelnussbaumer.com
DocumentRoot /var/www/amelineandraphael
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/amelineandraphael>
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>
zoziology
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName zoziologie.raphaelnussbaumer.com
DocumentRoot /var/www/zoziologie
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/zoziologie>
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
I have added a symbolic link to /etc/apache2/sites-enables
I've run sudo a2ensite amelineandraphael and sudo a2ensite zoziologie
and restart the apache server.
The sub-domain zoziologie.raphaelnussbaumer.com is working but amelineandraphael.raphaelnussbaumer.com redirect me to the default index.html at /var/www/.
Here are the .htaccess of /var/www/amelineandraphael:
SetEnv PHP_VER 5_4
# 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
Any idea ?
I think I found the solution. Although I'm not sure that's the only part of the solution:
sudo a2dissite 000-default
Unfortunately I can't comment yet as I don't have the rep, so sorry about this being an "answer".
I'm wondering if you have a DNS "A" record for that subdomain? You may have a wildcard DNS record though, which would make this a moot point

Apache ErrorDocument issue

i am trying to make my own 403 page but my apache doesn work correct.
I use
ErrorDocument 403
but it shows the same. This is my .htaccess:
# 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]
Here is my host settings:
<VirtualHost 127.0.1.15:80>
ServerAdmin webmaster#localhost
ServerName turik.loc
ServerAlias *.turik.loc
DocumentRoot /home/golars/proj/turik/
<Directory />
Options FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /home/golars/proj/turik/>
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
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/t4base_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
To 403 error i am going to turik.loc/img/hotels/ -where i dont have permissions to read&write. I would be graceful for a help.

Properly configure .htaccess

On localhost I have a file filename.html and an .htaccess in the same folder.
I need to figure out why my .htaccess is not working:
redirect 301 /filename.html http://www.google.com
I am on linux, I have configured the server:
sudo nano /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
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 All
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>
sudo service apache2 restart
I found:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^test\.html http://www.google.com/? [R=301,L]
my RewriteEngine is working.

Redirect non-existent dynamic virtual host folders with Apache

Is it possible to redirect to a certain URL if the directory for the virtual host doesn't exist? I have a VirtualHost setup below that lets me host a domain just by creating the folder, and pointing DNS to my server.
Here is my configuration for the VirtualHost
<VirtualHost *:80>
ServerAdmin webmaster#localhost
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/ [R=301,L]
VirtualDocumentRoot /var/www/%0
<Directory /var/www/%0>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
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 /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
You can manage it using rewriting rules.
Just after you rewriting rule to skip www :
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteCond /var/www/%1 !-d
# I think just /var/www/%{HTTP_HOST} works :|
RewriteRule .* http://example.com/nonexistant.php/$0 [L,R]