htaccess not working in ubuntu - apache

Hello a couple months ago I started a website project, after weeks last night I continued developing it on my windows pc were everything worked fine.
Today I ported it to ubuntu 12.04 lts and after starting up my apache / mysql tried to hit some website urls.(set up with vhost like so: tms.localhost/path...)
The Issue I'm facing and I have no idea why is that the clean urls and the mod_rewrite doesn't seem to work. My custom php redirection - page loading script isn't being called anymore(index.php).
Here is the htaccess that is unchanged since day 1. Need to mention that works only if I just enter the vhost url like so http://tms.localhost/ if i add anything after that I get the default apache 404 page.
#Debugging - Error reporting
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
#Commpression
<ifmodule mod_deflate.c="">
<filesmatch ".(js|css|html|png|jpg|jpeg|swf|bmp|gif|tiff|ico|eot|svg|ttf|woff|pdf)$"="">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>
Options All -Indexes +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# remove spaces from start or after /
#RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L,R=301,NE]
# remove spaces from end or before /
#RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L,R=301,NE]
# replace spaces by - in between
#RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1+$2 [L,R=301,NE]
# Remove trailing slash
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [L,R=301]
# Add trailing slash
#RewriteCond %{REQUEST_URI} !(/$|\.)
#RewriteRule (.*) %{REQUEST_URI}/ [L,R=301]
# Remove multiple slashes
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/{2,} [NC]
RewriteRule ^(.*) $1 [R=301,L]
# Clean url rewrite
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*\.(png|jpg|jpeg|bmp|gif|css|js|json)$ [NC]
#RewriteRule ^([^/]+/?.+)$ /index.php?req=$1 [L,QSA]
#RewriteRule ^(.*)$ /index.php?req=$1 [L,QSA]
RewriteRule ^(.*)$ /index.php [L,QSA]
</IfModule>
# Big thnx to anubhava for his regex help - linkedin.com/in/anubhava
UPDATE
The index.php works as a page file loader it doesn't contain any html.
Only the root url works and loads the corresponding php file, hence mod_rewrite is enabled.
htaccess fails to translate the rest of the requests I suppose ?
vhostfile tms.localhost
<VirtualHost *:80>
ServerAdmin webmaster#tms.localhost
DocumentRoot /var/www/tms
ServerName tms.localhost
#ServerAlias www.example.com
</VirtualHost>
modules phpinfo() :
core mod_log_config mod_logio prefork http_core mod_so mod_alias mod_auth_basic mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_autoindex mod_cgi mod_deflate mod_dir mod_env mod_mime mod_negotiation mod_php5 mod_reqtimeout mod_rewrite mod_setenvif mod_status

Well there was nothing wrong with it.
Apparently either the compression program or google drive (where I kept the project renamed .htaccess to htaccess...

Related

Can't get Anchor CMS rewriting to work

I'm currently attempting to install Anchor CMS on my Apache server.
I have successfully deployed it to the server. That is, when I go to www.domain.com, I am greeted with the default-themed front page and a test post :)
However, if I try to click the post, or go to the admin area, I get an error such as:
Not Found: The requested URL /posts/hello-world was not found on this server.
However, if I follow the (in this case) post link using a direct link, such as:
www.domain.com/index.php/posts/hello-world
It works completely fine. So, it appears to be a problem with the rewriting.
I found another problem on Stackoverflow exactly like mine, located here
Unfortunately, I did the same steps and nothing works. Just to recap, this is how my VirtualHost looks:
<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /var/www/domain.com/public_html
<Directory /var/www/domain.com/public_html>
AllowOverride All
Require all granted
</Dictory>
</VirtualHost>
And this is how my Anchor CMS config.app file looks:
return array(
'url' => '/',
'index' => '',
...(rest of the data here)...
As the documentation states to use an empty index in this default case.
My .htaccess currently looks like this:
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# 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/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
And it is located in the document root "public_html"
Sadly, even with these things configured, I still get the "Not Found" errors. I don't really know where to go from here :(
EDIT
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ http://google.com [R,L]
RewriteBase /
# 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/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
I tried to put in a general rewrite to the .htaccess file, and it seems like it's not being executed:
It appears that the mod-rewrite is not being loaded.
See your server configuration file (httpd.conf). There should be a statement as follows:
LoadModule rewrite_module modules/mod_rewrite.so
If the line starts with #, remove the # character. You can also use the command:
a2enmod rewrite
Also, try to shift your Rewrites outside of the IfModule block.
Options -indexes
RewriteEngine On
RewriteBase /
# 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/$1 [L]

Object not found! in xampp

I'm using creo's module system and laravel 4. mod_rewrite is enabled and I have a .htaccess I'm also using XAMPP. The weird thing is, if I use MAMP then it works fine but if I use XAMPP that is when I get the Object Not Found error. I would like to use XAMPP because it is much more easier to create a virtual host with it then it is with MAMP.
In my url I have
http://localhost/test-modules/index.php/admin/content
but I need it to be
http://localhost/test-modules/admin/content
here is my .htaccess
Order allow,deny
Allow from all
<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]
# Disallow access to following directories
#RewriteRule ^vendor($|/|/.*|./*) – [L,R=404]
#RewriteRule ^app($|/|/*|/.*) – [L,R=404]
</IfModule>
Do yourself a favor and don't use either MAMP or XAMP. Use homestead.
http://laravel.com/docs/4.2/homestead
To give you some guides:
https://laracasts.com/lessons/say-hello-to-laravel-homestead-two

Trailing slash in url and virtual host

I have a laravel project on localserver and want it to work even when the trailing slash is added to the url. It is working fine when accessed with localhost url. The htaccess is as follows:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /LaravelProject/public/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ $1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Trying to access page like
http://localhost/LaravelProject/public/login
and
http://localhost/LaravelProject/public/login/
is working fine.
However I have also VirtualHost defined like this
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/LaravelProject/public"
ServerName LaravelProject.dev
ServerAlias www.LaravelProject.dev
ErrorLog "c:/wamp/logs/apache_error.log"
CustomLog "c:/wamp/logs/access.log" common
</VirtualHost>
Via url laravelproject.dev, I can access the document root and can see the "You have arrived." But when I try to access other url say laravelproject.dev/login, it gives me 500 Internal Server Error.
If I remove the RewriteBase from .htaccess and modify the RewriteRule as
RewriteRule ^(.*)/$ /$1 [L,R=301]
then the urls laravelproject.dev/login and laravelproject.dev/login/ work fine.
If I do this, again the problem persists with localhost url with trailing slashes and the
url http://localhost/LaravelProject/public/login/ redirects to http://localhost/login.
I want to be able to use both localhost and virtualhost urls with and without trailing slashes and give the same result. As it seems, it is one or the other for me.
I don't think you need any of these lines in your .htaccess file. I have got mine set up like this on a couple of projects and it works perfectly fine:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Url rewrite subfolder to root and forbid accessing subfolder

I have drupal installed in a subfolder drupal, but I want to access pages as it is in root folder: http://www.example.com instead of http://www.example.com/drupal
I'm able to have this working, but it's also working with url containing subfolder, so I have http://www.example.com and a clone site in http://www.example.com/drupal
What is the rule to forbid access to subfolder?
I want all url starting with http://www.example.com/drupal being forbidden.
This is .htaccess in / directory:
Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*+)$ drupal/$1 [L,QSA]
</IfModule>
And this is drupal .htaccess in /drupal/ directory:
Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 index.php
DirectoryIndex index.php index.html index.htm
# Override PHP settings that cannot be changed at runtime. See
# sites/default/default.settings.php and drupal_initialize_variables() in
# includes/bootstrap.inc for settings that can be changed at runtime.
# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
php_flag magic_quotes_sybase off
php_flag register_globals off
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
<FilesMatch \.php$>
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off
</FilesMatch>
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
# Block access to "hidden" directories whose names begin with a period. This
# includes directories used by version control systems such as Subversion or
# Git to store control files. Files whose names begin with a period, as well
# as the control files used by CVS, are protected by the FilesMatch directive
# above.
RewriteRule "(^|/)\." - [F]
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteBase /drupal
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
#RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Rules to correctly serve gzip compressed CSS and JS files.
# Requires both mod_rewrite and mod_headers to be enabled.
<IfModule mod_headers.c>
# Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
# Serve correct encoding type.
Header append Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
It looks like you're rewriting stuff to the /drupal/ directory, so you don't want to completely forbid access, otherwise going to http://www.example.com will be denied because it gets rewritten to /drupal. I'm assuming you want to disable requests that are directed to the drupal directory, so you'd need to add this somewhere:
RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ /drupal/
RewriteRule ^drupal - [F,L]
Adding this to the top of the .htaccess (just under RewriteEngine On) in your document root should be sufficient. If not, try adding it to the one in your drupal directory (just under RewriteEngine On).
I solved this adding these two lines after RewriteEngine on in /drupal/.htaccess:
# deny access to url starting with /drupal/
RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ /drupal/
RewriteRule .* - [F,L]
Using R=403 avoids problems with drupal "not found" handler: ErrorDocument 404 drupal/index.php
Try to change this in your .htaccess in / directory:
Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
# if access is straight to drupal (= no rewrite rule)
# notify in query string:
RewriteRule (drupal/(.*)) $1?straight=1 [QSA]
RewriteRule ^(.*+)$ drupal/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteRule ^(.*+)$ drupal/$1 [L,QSA]
</IfModule>
Add this in your drupal dir .htaccess file just after RewriteEngine On:
RewriteEngine On
RewriteCond %{QUERY_STRING} straight=1
# "not found" 404 :
RewriteRule .* - [R=404,L]
Tell me if it works :)

DirectoryIndex not working because of mod_rewrite?

Requests to www.domainname.com and domainname.com should display index.html, not index.php as it does now.
This is the .htaccess file:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tried adding a DirectoryIndex index.html to the file, but that did not work. I suspect that has something to do with the mod_rewrite stuff, but being an apache-n00b I am really just grasping for straws.
Can I add a rewriterule, or what should I do?
Strangely, your .htaccess works fine for me and I get index.html when I request the directory.
You might try inserting this rule:
RewriteCond ^/$ /index.html [L]
If that doesn't work, get some debug information:
RewriteLog "/some/writable/path/rewrite.log"
RewriteLogLevel 3