change directory name in url only htaccess - .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.

Related

Symfony .htaccess DirectoryIndex not working

I am deploying my symfony application to production, i have placed the symfony application in the root folder
/var/www/html and have set the apache2 root directory to /var/www/html/web but the DirectoryIndex in the .htaccess file is not redirecting to the file app.php
On the url xxx.xxx.xx.xx/ i get the list of all the documents in /var/www/html/web folder, and if i do xxx.xxx.xx.xx/app.php the application loads.
I don't understand how to get the DirectoryIndex in the .htaccess to work.
I have been going through the following stack questions types but they don't work for me:
Redirect all requests to web/app.php in Symfony
Symfony: htaccess to hide app.php or app_dev.php
symfony2 rewrite rules .htaccess app.php
Another post suggested to set the apache2 root directory as /var/html instead of /var/html/web but that doesn't work either. Because the url xxxx.xxx.xx.xx/ deplays the content of the directory /var/html
The closest to a solution i came to was to rename the file app.php to index.php which got the root url xxx.xxx.xx.xx/ to load, but then all the 'sub' urls ( like xxxx.xxx.xx.xx/offer/9/Alternance_Apprentissage_graphiste_chez_Eggs) fails with a 404 Not Found error.
It is due to .htaccess file not redirecting properly the urls, because the url xxxx.xxx.xx.xx/app.php/offer/9/Alternance_Apprentissage_graphiste_chez_Eggs works fine.
My .htaccess file looks like this (it is the default generated file):
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
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>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Any help appreciated. This is critical because i cannot get my application to go on production.
UPDATE
#shevron 's is right. From his answer "It is possible that .htaccess files are not parsed at all by your Apache setup." and "Check your main Apache configuration for AllowOverride on that directory. Try to set it to AllowOverride All and restart your Apache - see if that works."
I did the following:
I set my Apache Configuration as following :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/web
<Directory "/var/www/html/web">
AllowOverride All
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This did not work.
#shevron did i not write that properly?
But further i put all the configurations from the .htaccess file into the Main Apache Configurations as such and this made the redirection work:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/web
<Directory "/var/www/html/web">
AllowOverride All
Allow from All
</Directory>
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
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>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
So now the redirection is working.
It is possible that .htaccess files are not parsed at all by your Apache setup (in fact, this is probably recommended for single-tenant production servers for both performance and security reasons).
Check your main Apache configuration for AllowOverride on that directory. Try to set it to AllowOverride All and restart your Apache - see if that works.
If it works, I suggest moving the contents of your .htaccess file into a <Directory> or <VirtualHost> section in the main Apache configuration file (or better yet in a separate file included by it) and setting AllowOverride None.
I found this: http://symfony-check.org/permalink/optimize-apache-avoid-htaccess which is specific for Symfony with some details, although I don't know if its up-to-date as I'm not a Symfony user.

hide directory for symfony2 app in url

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>

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)

.htaccess equivalent of baseurl?

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.

Resources