I have a problem with mod_rewrite and I cannot understand what is wrong.
First I did a query string rewrite to have something like this:
/api/call
instead of
/api.php/call.php
This did not work as when printing the request, it was empty, whereas if I enter the url
/api/call/test=5
the request parameters returns with test=5
I added the Allow from all in the virtual host but it still did not work.
I then tried to disable mod_rewrite and to my amazement the call /api still loaded /api.php and /index loaded /index.html.
This is really strange as this is not supposed to happen if mod_rewrite is disabled. In fact, if I try it on my local WAMP server, a 404 not found is shown.
This means that somewhere there is some sort of rewrite on the Ubuntu server but I cannot understand how this is working with mod_rewrite being disabled.
Any ideas?
Thanks in advance
EDIT (sites-available contents)
<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 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>
Apache was restarted successfully with restart not reload.
You have MultiViews enabled on /var/www.
http://httpd.apache.org/docs/current/mod/mod_negotiation.html#multiviews
Try the command:
a2dismod rewrite
Then restart apache. Also make sure there is no .htaccess file in the root directory specifying mod-rewrite settings.
Related
I'm using Google VM instances on Google Cloud Platform for running my live server. I'm also using CodeIgniter to build of my server. It can load the default route when entering the page but when going to other routes, it shows Apache 404 error:
Not Found
The requested URL was not found on this server.
Apache/2.4.29 (Ubuntu) Server at 35.186.147.249 Port 80
My Apache config file at /etc/apache2/sites-available:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<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 All
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
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>
I looked up online and most people say it is an Apache problem but I'm not too sure. I'll share any of the files in order to fix this issue.
The line DocumentRoot /var/www/html determinate the base of your files, I reviewed the IP that you put and i can see the next folder and access correctly:
j/
medical-survey/
temp/
Here is the link to understand more about DocumentRoot, so you can define where you require the default folder route for your web files. In case you require to have different links of your web development you can follow this link to configure the virtual hosts. Hope this is what you were looking for.
I wanted to set up a virtualhost for my apache2 running on my computer. So when I browse to: "invision.jan.pcsg" I get the page contents/folder structure from "/var/www/html/invision"
This is the virtualhost file "invision.jan.pcsg.conf" I created:
<VirtualHost invision.jan.pcsg:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/invision
ServerName invision.jan.pcsg
ServerAlias hkl.mor.pcsg hkl_at.mor.pcsg
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /var/www/html/invision/>
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
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>
When I browse to "invision.jan.pcsg" now, I get redirected to localhost and the "php is working"-page is displayed.
When browsing to "jan.pcsg" the folder contents of "/var/www" is displayed.
Does anyone have an idea why this happens?
I had the same issue but in my case I realized I had forgotten to enable the host .conf file.
sudo a2ensite myvhost.conf
Then I just reloaded apache and everything worked out as expected.
Change your DocumentRoot to directory where your web application ('view' if its MVC) is located.
Usually its : DocumentRoot /home/www-data/ /
I've been reading up on this on the web, but still could not figure out how to implement it properly. I'd greatly appreciate if you could help me understand how to make url rewrite work without .htaccess.
To check if mod_rewrite is enabled, I ran command ~# sudo apachectl -t -D DUMP_MODULES. It produced, among others the following module: rewrite_module (shared). I don't know if it is the same as mod_rewrite?
Folder /etc/apache2/mods-enabled/ has file rewrite.load
I'm not clear which file exactly I should add rewrite rules to?
File httpd.conf located in /etc/apache2/ is empty. However there's a file named 000-default located in /etc/apache2/sites-enabled/ and it looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
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 ${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>
I'm not clear at all where I should add rewrite rules. I tried adding them to this 000-default file into <Directory /var/www/> section, but it did not work.
You put the rewrite code in the directory block where you're have the .htaccess file (if you use them). For example if /var/www is your docroot, you could put it their:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
</Directory>
If you are using apache 2.2.16 or newer, use
FallbackResource /index.php
AS the title says, my rewrite rules does not work when I upload it to my server (Ubuntu LTS). The .htaccess-file is in play, but does nothing.
mod_rewrite is loaded, I've verified that several ways. I tried writing rubbish text in the .htaccess file and got a 500 internal error, so the file seems to be in the loop. The virtualHost configuration has "allowOverride All".
The .htaccess file consists of a series of rewrite rules, such as:
RewriteRule ^webshop$ index.php?page=webshop [QSA]
RewriteRule ^webshop/([0-9]+)$ index.php?page=webshop&catID=$1 [QSA]
On the server I have to virtualhosts, one public server and one testing server. The public server works fine, all rewriterules are similar to above and works. It's the virtualhost for testing that doesn't want to play. One server, one IP, two FQDNs.
Ideas?
EDIT - Here's the VirtualHost config:
<VirtualHost *:80>
ServerAdmin beta#example.com
ServerName beta.example.com
DocumentRoot /var/www/beta/www-root
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/beta/www-root>
AddDefaultCharset utf-8
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from (Two IPs omitted)
</Directory>
<Directory /var/www/temp>
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.beta.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/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>
The problem seems to be that there is a folder with the same name as (a part of) the regex. I have a file called "webshop.php", and for some reason the regex ^webshop$ then fails (servers seems to prefer the actual folder/files rather than a local rewrite).
I'm trying to setup apache virtual host on Mint linux. It kinda works, but some images are not available. For example http://test.local/icons/world.png returns 404 even if image exist. When I check log it says it's looking for image at /usr/share/apache2/icons/world.png even if I setup my DocumentRoot to /var/www/test.local/public_html
This is how I did this. copy /etc/apache2/sites-available/default to test.local and edit like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.local
DocumentRoot /var/www/test.local/public_html
<Directory /var/www/test.local/public_html/>
<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 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>
Then I edit /etc/hosts and include 127.0.0.1 test.local in it. Run a2ensite test.local and restart apache.
What I try to do is map folder in my /var/www/test.local/public_html to http://test.local is there anything I'm missing, or easier way to do this.
Also to mention there is no .htaccess file in root directory of project, or in icons directory.
RESOLVED :)
This is 2nd time I'm answering my own questions here on SO. I actually was researching 2 days and found answer few hours after posting here.
Answer was that this is default Apache alias
Alias /icons/ "/usr/share/apache2/icons/"
Even if I couldn't find it in apache2.conf or in conf.d directory, it looks like it's there in /etc/apache2/mods-available/alias.conf under my Mint distribution (I guess all Debian distro will have similar path). All I needed to do is to comment out this alias and it works.