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)
Related
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.
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>
The app.php is hidden from url like this:
RewriteEngine On
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
But before it, there is: /symfony/web/
How to hide it?
Change your DocumentRoot in your Apache configuration to point to the web/ directory.
Edit /etc/httpd/conf/extra/httpd-vhost.conf (your path may vary when using other distributions like Ubuntu):
...
<VirtualHost *:80>
...
DocumentRoot /path/to/your/webapp/symfony/web
<Directory /path/to/your/webapp/symfony/web>
...
</Directory>
</VirtualHost>
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.
I'm trying to install Symfony on a shared server and am attempting to duplicate the httpd.conf command:
# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080
# This is the configuration for your project
Listen 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
DocumentRoot "/home/sfproject/web"
DirectoryIndex index.php
<Directory "/home/sfproject/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /home/sfproject/lib/vendor/symfony/data/web/sf
<Directory "/home/sfproject/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I need to do so using .htaccess
The redirect portion was done in the root using the following:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^symfony.mysite.ca [nc]
rewriterule ^(.*)$ http://symfony.mysite.ca/web/$1 [r=301,nc]
For the alias, I've tried using:
RewriteBase /
but no success.
The main issue is that the index.php file residing in the /web folder uses the /web path in its path to images and scripts. So instead of
href="/css/main.css" //this would work
it uses
href="/web/css/main.css" //this doesn't work, already in the /web/ directory!
Any ideas? Thanks!
You can use...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
to prevent urls that refer to actual files from being rewritten, thus preventing the generic rewrite from adding a second /web into the URL.