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.
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.
I have an application and the entry point is index.php in /var/www/html/quote directory. The application is using slim framework to deliver json api. So I tested the application using php -S localhost:8080 but now I'm ready to upload to my hosting service so I want to be able to test the app by typing localhost/quote. I enabled mod_rewrite in apache2. Also I added this to the directory where index.php is localted
.htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
finally, I modified the apache2.conf file and change directive like this. changing AllowOverride to All
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Now when I type http://localhost/quote. I'm getting "page not found"
what am I missing?
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
I'm trying follow the Getting started: A skeleton application of zend framework at this link. I'm using xampp as a host.
What I did
following the documentation, I downloaded the .zip skeleton tutorial file in github and put the extracted file in this path
C:\xampp\htdocs\practice\zf2-tutorial
using gitbash composer I run composer install directly from the given path and successfully installed its dependencies.
in httpd.conf file I added this
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost </VirtualHost> <VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/practice/zf2-tutorial/public
ServerName xf2-tutorial.localhost
SetEnv APPLICATION_ENV "development"
<Directory C:/xampp/htdocs/practice/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory> </VirtualHost>
and in host file in this location c:\windows\system32\drivers\etc\ I added this
127.0.0.1 xf2-tutorial.localhost
After restarting apache, and visit this
http://xf2-tutorial.localhost/
in the browser it render successfully the index.page but when I try to visit
http://xf2-tutorial.localhost/1234
I get 404 error, what I did, I checked tha .htaccess if correct, this was the content of the htaccess
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
I added this,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [NC,L]
But still I get 404 error
Any Idea, what to do with it?
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.