I would like to change my url using only .htaccess, how can i change my url from this : http://s1rd-ubuntu-01/vpscraplist/web/app_dev.php/myproject/ to this http://vpscraplist/platform/ or this http://vpscraplist/
i have also more pages on my project as http://s1rd-ubuntu-01/vpscraplist/web/app_dev.php/myproject/add and http://s1rd-ubuntu-01/vpscraplist/web/app_dev.php/myproject/edit ...
I've already used thoses scripte but not work for me :(
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app_dev.php - [L]
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_dev.php [QSA,L]
or this one :
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^/web/app_dev.php - [L]
RewriteRule ^/web/app.php - [L]
# Fix the bundles folder
RewriteRule ^bundles/(.*)$ /web/bundles/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /web/app.php [QSA,L]
RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]
Thank you and sorry about my english !
In my opinion the best approach is to keep the default htaccess of symfony, and to configure your apache vhost as explained there:
http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html
(don't forget to enable the apache rewrite if it is not dude: sudo a2enmod rewrite )
create the vhost file:
sudo nano /etc/apache2/sites-available/yoursite.conf
with:
<VirtualHost *:80>
ServerName mydomain.net
ServerAlias www.mydomain.net
DocumentRoot /var/www/myprojectSymfony/web
<Directory /var/www/myprojectSymfony/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
Once you have have created your virtual file, you must enable them
sudo a2ensite yoursite.conf
When you are finished, you need to restart Apache to make these changes take effect:
sudo service apache2 restart
Related
**I'm working on an apache secured web server hosted on an ubuntu-server.16.04
I'm sending on prod my first project on symfony and I did quite well since now. I'm trying to rewrite url so when I want to go on my project dashboard, the url would be "../dashboard/" instead of (actually like this) "../index.php/dashboard/"
But when I try to go on this url, the server redirect me out of the symfony app and throw me a basic apache 404 error, not a symfony handled error.
I think this can be edited in the .htaccess file but I can't find out how to make him perform all url as symfony routes, that's my question.
Tried multiple code found on google
htaccess
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<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 ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
You need to enable apache rewrite.
Please follow these steps :
In a terminal use the following commands:
$sudo a2enmod rewrite
Change AllowOverride in apache conf file:
$sudo nano /etc/apache2/apache2.conf
Change the AllowOverride from None to All in this block
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
At last, restart apache2
$sudo service apache2 restart
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>
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.
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.