Debug .htaccess syntax error - .htaccess

I have the following code:
# Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^salom.dev[nc]
RewriteRule ^(.*)$ http://www.salom.dev/$1 [r=301,nc]
# 301 Redirect Entire Directory
RedirectMatch 301 /admin(.*) /vendor/aheinze/cockpit/$1
# Change default directory page
DirectoryIndex /site
# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# Prevent directory listings
Options All -Indexes
I keep getting 500 errors but I can't find the problem any ideas?
Here is the conf file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName salom.dev
DocumentRoot /home/otis/Developer/salom
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/otis/Developer/salom/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Also is there a way to debug these errors using the dev tools or potentially the logs?

DirectoryIndex is a file not a directory and you have a missing space before `[nc].
Try this .htaccess:
# Change default directory page
# DirectoryIndex /site
# Rewrite to www
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^salom\.dev$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# 301 Redirect Entire Directory
RewriteRule ^admin(.*) /vendor/aheinze/cockpit/$1 [L,NC,R=301]
# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

Related

apache redirect /url1/* to /url1/index.html

I changed the context url from:
domain.name/url1 to domain.name/url2
I want to have a 301 redirect of all URLs from
domain.name/url1/* to the static file domain.name/url2/moved.html and show a static maintenance page
The rewrite rules should not take into account any other URLs except domain.name/url1/* for this redirect
url1 and url2 are subfolders in the apache directory /var/www/home/
The apache configuration is:
Listen 9082
<VirtualHost *:9082>
ServerName domain.name
DocumentRoot "/var/www/home"
<Directory />
Require all denied
</Directory>
<Directory "/var/www/home">
Require all granted
RewriteEngine on
AllowOverride all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
</VirtualHost>
You may try this code in your url1/.htaccess:
DirectoryIndex index.html
RewriteEngine On
RewriteRule ^index\.html$ - [NC,L]
RewriteRule . /url1/ [L,R=301]

Cannot found the route without the app_dev.php

When I go to my website like this :
example.com/ or
example.com/app_dev.php
That works fine.
But when I try to go to a different route like
example.com/api/route/option
I got an error 404, however when I go to
example.com/app_dev.php/api/route/option
That is working fine.
This is my .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^app_dev.php - [L]
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ app.php [QSA,L]
RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
And this is my virtualhost
<VirtualHost *:80>
ServerName example.com
ServerAdmin my_mail
DocumentRoot /var/www/html/example/web/
DirectoryIndex app_dev.php
<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>
Got an idea ?
Thanks !
Your virtual host file doesnt enable overrides meaning your .htaccess file isnting being read. Try adding this to your virtual host file:
<Directory /var/www/html/example/web/>
AllowOverride None
Order Allow,Deny
Allow from All
</Directory>
You may also want to look into other setup options as documented here: http://symfony.com/doc/current/setup/web_server_configuration.html

Return 404 for the /web directory Symfony 3

All my links are accessibles by mysite.com but also with mysite.com/web/
I would not like to redirect /web to / but, i would like to return a 404 for ^/web. I think it's possible cuz i saw a lot of symfony projects which return 404 error for the /web path
Thanks you all !
You need to modify your apache configuration so the document root points to /web folder.
Your apache config file needs to look something similar to this:
<VirtualHost *:80>
ServerName www.mysite.com
ServerAlias mysite.com
ServerAdmin contact#mysite.com
RewriteEngine On
DocumentRoot your_site_path/web
<Directory your_site_path/web/>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
</Directory>
</VirtualHost>

Drupal 7 rewrite not using .htaccess

I'm trying to enable the rewrite function in drupal 7 without using the .htaccess file since it should only be used if you do not have root access to the server (accordingly to apache's website)
Without any further adieu, here is my configuration
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DirectoryIndex index.php
DocumentRoot /var/www/example.com/public
ErrorDocument 404 /index.php
LogLevel warn
ErrorLog /var/www/example.com/log/error.log
CustomLog /var/www/example.com/log/access.log combined
<Directory "/var/www/example.com/public">
Options -Indexes +FollowSymLinks +ExecCGI
AllowOverride None
Order allow,deny
Allow from all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
</Directory>
</VirtualHost>
The rewrite configuration worked when I had it in the .htaccess file but not when I put it inside the vhost file.
Can you guys see anything wrong here?
I think your rewrite rule should not contain the '/' prefix now that it's not a .htaccess anymore. Soo try with:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Removing .htaccess reference is a good idea. You should put the AllowOverride None on a <Directory /> instruction so that this start from the root of the filesystem. If think you do not need the +ExecCGI also. If you want to go deeper in apache config for Drupal without .htaccess check also this detailled resource.

proper userdir.conf for this .htaccess

The story behind...
Ok, I was experimenting things with my netbook...without having backup files. Yes, I'm a moron :D
The Problem
I have this .htaccess file in my userdir which was working properly before I screwed up my partion:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /~dierre/DierReLabS/
RewriteRule ^(tutorials|me|not-found|add)$ $1/ [R=301,L]
RewriteRule ^me/$ me.php [L]
RewriteRule ^style/$ style.css [L]
RewriteRule ^logo/$ logo2.png [L]
RewriteRule ^add/$ add.php [L]
RewriteRule ^tutorials/$ tutorials.php [L]
RewriteRule ^tutorial/([a-zA-Z0-9\-]+)/$ tutorial.php?tut=$1 [L]
RewriteRule ^not-found/$ 404.php [L]
# This is a real directory...
RewriteCond %{REQUEST_FILENAME} -f [OR]
# Or it's a real file...
RewriteCond %{REQUEST_FILENAME} -d
# And it's not not-found/...
RewriteCond $0 !=not-found/
# And it's not the root
RewriteCond $0 !=""
# And it's not any of the above due to an internal redirect...
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# So cause a 404 response (you could redirect to 404.php if you want)
RewriteRule ^.*$ - [R=404,L]
ErrorDocument 404 /~dierre/DierReLabS/not-found/
In the userdir this .htaccess does not work properly with the default parameters in userdir.conf. I do not have anymore that configuration. The current configuration is:
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>
I really can't recall what I did. Can you help me?
Thanks God for forsaken laptop! I've started today my Thinkpad and it was there the configuration with a non-updated version of the site.
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
#AllowOverride FileInfo AuthConfig Limit Indexes
AllowOverride All
#Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Options Indexes FollowSymLinks
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>

Resources