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

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]

Related

change directory name in url only htaccess

I have a directory in my web root projectae/project/index.php and I want to change directory name only in url but in root still have the of projectae so I want to change
localhost/projectae/project/index.php
to
localhost/ae/project
I did some try on my htaccess but none succeed
I did try :
RewriteCond %{THE_REQUEST} ^GET\ /projectae/
RewriteRule ^projectae/(.*)$ /ae/$1 [L]
I also tried
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pojectae/project/$ /ae/project/$1 [L]
I did clear cache nothing work; I did restart apache nothing work
my config file :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
Your description suggests that you want to rewrite the other way round:
RewriteEngine on
RewriteRule ^/?ae/(.*)$ /projectae/$1 [L]
A typical combination would be to combine rules for redirection and rewriting:
RewriteEngine on
RewriteRule ^/?projectae/(.*)$ /ae/$1 [R=301,L]
RewriteRule ^/?ae/(.*)$ /projectae/$1 [L]
Those rules will work likewise in the http servers central host configuration or in a distributed configuration file (".htaccess" style file). If you really have to use such a distributed file then take care that it's consideration is enabled in your host configuration (see the documentation for the AllowOverride directive) and that above rule is placed in such a file inside the DOCUMENT_ROOT folder of the http host.

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>

Debug .htaccess syntax error

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>

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.

htaccess mod rewrite in an aliased folder not working

I have a site "new.mysite.com" in Drupal.
In the vhost file I have a directory "weight-loss" pointing to another location on the server for this website.
In that folder I have a mini-site based on Zend Framework which is using mod_rewrite.
The mod_rewrite is not working, and I'm thinking it's because this folder is an alias because the exact same mini-site works in another location without being in an aliased folder.
The mini-site in in "/home/weight-loss/admin/". The .htaccess file is "/home/weight-loss/admin/.htaccess"
http://new.mysite.com/weight-loss/admin/dashboard/index
should be :
http://new.mysite.com/weight-loss/admin/index.php?module=dashboard&controller=index
What am I doing wrong?
The vhost settings
<VirtualHost 192.168.100.142:80>
ServerAdmin serveradmin#bbgi.com
DocumentRoot /home/drupal_1
ServerName new.mysite.com
ServerAlias mysite.com www.mysite.com
Alias /weight-loss /home/weight-loss/
ErrorLog /var/log/httpd/mysite.com_err_log
CustomLog /var/log/httpd/mysite.com_log special
<Directory /home/drupal_1>
Options FollowSymLinks Includes ExecCGI
AllowOverride All
DirectoryIndex index.html index.htm index.php
</Directory>
</VirtualHost>
The .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /weight-loss/admin/index.php [NC,L]
Duplicate the <Directory /home/drupal_1>...</Directory> and change the /home/drupal_1 to /home/weight-loss. That should enable htaccess (and therefor also mod_rewrite)

Resources