The issue
I'm writing a cgi script in c++. All works well as long as I go in to the precise url: http://localhost:90/joppli.bot
Now I'm trying to make a simple redirect to from everything to my cgi script. eg:
http://localhost:90/
http://localhost:90/foo
http://localhost:90/foo/bar
...should all render the same content as entering http://localhost:90/joppli.bot
Files
.htaccess
RewriteEngine On
RewriteRule (.+)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ joppli.bot [NC,L]
virtual host
<VirtualHost *:90>
DocumentRoot /var/www/joppli-bot
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
SetHandler fastcgi-script
<Directory "/var/www/joppli-bot">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/www/joppli-bot/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/www/joppli-bot/log/apache2/access.log combined
</VirtualHost>
files at /var/www/joppli-bot
.htaccess
joppli.bot -> /home/erik/NetBeansProjects/joppli.bot/dist/Debug/GNU-Linux-x86/joppli.bot
log
+ apache2
+ access.log
+ error.log
Thanks to Justin Iurman Who wrote the following as a comment, witch solved most of it:
In <Directory "/var/www/joppli-bot"> block, replace AllowOverride None
by AllowOverride All (otherwise your htaccess is disabled)
I also added DirectoryIndex joppli.bot at the bottom of my .htaccess file to route all trafic from root directory to the script as well..
Related
My current setup on my production server is like the following:
there are two folders in
var/www/html
These two folders are named:
xyz
doge
Now I would like to place all requests to IP/doge into the doge folder.
This seems to work, but only the index page is working. Using the already created routes like for example:
ip/doge/login
will result in a 404 error page of apache.
Here's my apache config:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/xyz/public
Alias "/doge" "/var/www/html/doge/public"
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html/xyz/public/>
AllowOverride All
</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
</VirtualHost>
Any idea where's my fault? I haven't changed the .htaccess in the public folder of each laravel project. This .htaccess looks like:
<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>
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
I have tried several ways to remove index.php from my URL (http://www.example.com/index.php/login), as well as redirecting www to the non-www URL.
Here is my default Apache VirtualHost file:
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/public/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/public/>
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>
Now I have added the following in to this file:
Redirect 301 / http://example.com
But this has not worked, I just get a redirect loop message. I also have the following .htaccess:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
To which I've added:
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
But this does not work either.
The other issue is that for all of my routes I have to include index.php, like http://example.com/index.php/test
It's as if my .htaccess file is being ignored.
The server is a DigitalOcean Droplet running Ubuntu 13.04 x64. It has PHP 5.4.9 and Apache 2.2.22.
Any help would be very much appreciated. Thanks.
Thanks to anlutro in #laravel IRC chat, he pointed out that mod_rewrite may not be enabled. Usually this is on by default in all the servers I've ever worked with so it didn't click, as I've never had to enable it but on this DigitalOcean server, it wasn't.
I used:
a2enmod rewrite to enable it and then I restarted apache. All is good.
Cheers
I have read a lot of topic with the same problem but i do not find the solution... please help me. I have a lamp into ubuntu server. My document root is /home/utente/ into this dir I have another dir (turni) with a codeigniter web app. The web app works fine with the "index.php" into the url, but I want to eliminate it. I have this configuration:
config.php into codeigniter:
$config['index_page'] = '';
.htaccess:
RewriteEngine On
RewriteBase /
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]
/etc/apache2/sites-available/default:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/utente
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/utente/>
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>
When i open a link of the web app with without eh "index.php" into the url, the server o me this error: The requested URL /turni/auth/login was not found on this server.
Why??? If i put the index.php like /turni/index.php/auth/login all works fine....
Thanks for help and sorry for my english :D
Add .htaccess to your server root directory and change the rewrite base to
RewriteBase /turni
assuming your codeigniter is present in /var/www/turni
I have two apache servers both have identical settings, I cloned the apache config files, and changed the ServerName part only. When I type mysite.com/somestuff it should rewrite to index.php it does it on my old server, but not my new. I have made sure the .htaccess is there when I do mysite.com/index.php/somestuff it works, but like my first site I need it to work with mysite.com/somestuff.
I am really banging my head against the wall here is my .htaccess and apache config file
#.htaccess file
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}index.php/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
Now for my apache config
<VirtualHost *:80>
ServerAdmin user#host.com
ServerName mysite.com
DocumentRoot /home/richardw/www/halogen/web
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/richardw/www/halogen/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
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>
My apologizes if this is a repost, but I've been searching all over and i'm about to lose it.
When you go to http://mysite.com/, are you redirected to http://mysite.com/index.php/?
If this is happening, that means mod_rewrite is not loaded in your new server. You need to make sure it's loaded in your apache's server config file. See this answer for some instructions on how that works for apache.
The reason why the redirect is working is because of this container:
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
This essentially says "if mod_rewrite is not loaded", then if mod_alias is loaded, it redirects the root request to /index.php/. So if the redirect is happening, mod_rewrite is not loaded.
Have you try to comment or remove this line
Options +FollowSymlinks
in your .htaccess?