views:

45

answers:

1

Hello,

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!

A: 

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.

Amber
Thanks for the tip, but I'm still left slightly confused. I understand that I can use your example above to identify if a file doesn't exist.What RewriteRule can I use that would:1. Check to see that the file its looking for starts with /web2. Replace that path with the same path, but chopping the /web off the start.Is that possible?
RyanPriceDotCa
`/web/css/main.css` is an *absolute* path - even if it's referenced from a file in the `/web` directory, since it begins with a `/` it will be loaded relative to the document root, not any subdirectory within it. Thus, my guess is that the problem isn't actually needing to *remove* `/web` from the path, but instead simply prevent your rewriterule that *adds* it from triggering in cases where it's already pointing to the proper file. Hence my suggestion of the conditions, to prevent the rewriterule from triggering when the path is already correct.
Amber
Thanks! That clears things up.
RyanPriceDotCa