4

I am developping a website/web-app locally, which includes many ajax calls etc... My problem is everytime I have to include app_dev.php to the url - so when I go on prod I'll need to search and replace these urls..

Is there a way via apache to hide app_dev.php ? I read many questions on that one but no solution worked for me.

What I already did was adding this:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/wamp/www/web"
    DirectoryIndex app_dev.php
    ServerName dummy-host.example.com
    ServerAlias localhost
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
    <Directory "C:/wamp/www/web">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

to my httpd.conf but it is completely ignored...

I am working with WAMP 2.2

3 Answers 3

3

I changed my web/.htaccess to the following, :

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    #<IfModule mod_vhost_alias.c>
    #    RewriteBase /
    #</IfModule>

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>

I added the following to my httpd.conf:

DocumentRoot "c:/wamp/www/web"
<Directory "c:/wamp/www/web">

And to my httpd-vhosts.conf (C:\wamp\bin\apache\apache2.4.2\conf\extra) :

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/wamp/www/web"
    DirectoryIndex app_dev.php
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
    <Directory "C:/wamp/www/web">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>
Sign up to request clarification or add additional context in comments.

Comments

0

I would go with a more consistent approach with this bundle:

FOSJsRoutingBundle

Then you can generate routes by their name, and app_dev.php addition will happen just in dev environment.

2 Comments

It seems this bundle adds an extra js file to do the job? Isn't it a bit exaggerating?
It's a simple file, you'd be compressing and minifying as well. This way your routes are consistent, i.e. if you change them in the server side code, such changes are reflected in js code as well.
0

It appear you are trying to set a development environment up for Symfony.

A simpler solution would have been to just create the virtual host and tell it to not use the .htaccess as it is the .htaccess file that is causing your Virtual Host setup to get overridden.

Remember .htaccess gets applied after whatever you do in the httpd.conf or httpd-vhosts.conf files.

Virtual Host for development mysite.dev

<VirtualHost *:80>
    ServerName mysite.dev
    ServerAlias www.mysite.dev
    DocumentRoot e:/testing/mysite/web
    <Directory  "e:/testing/mysite/web/">
        // disable the .htaccess in the web folder
        // from undoing the attempt to go straight to app_dev.php
        AllowOverride None

        Require local

        // this forces app_dev.php to be run
        <IfModule rewrite_module>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app_dev.php [QSA,L]
        </IfModule>
    </Directory>
    ErrorLog "D:/wamp/logs/mysite.dev.apache.error.log"
    CustomLog "D:/wamp/logs/mysite.dev.apache.access.log" combined
    php_value error_log "D:/wamp/logs/mysite.dev.php.error.log"
</VirtualHost>

Virtual Host for testing in the PROD environment

<VirtualHost *:80>
    ServerName mysite.dev
    ServerAlias www.mysite.dev
    DocumentRoot e:/testing/mysite/web
    <Directory  "e:/testing/mysite/web/">

        AllowOverride All

        Require local

    </Directory>
    ErrorLog "D:/wamp/logs/mysite.prod.apache.error.log"
    CustomLog "D:/wamp/logs/mysite.prod.apache.access.log" combined
    php_value error_log "D:/wamp/logs/mysite.prod.php.error.log"
</VirtualHost>

Now you can leave the .htaccess file as it is, as it may be very relevant when you come to move this site to a live server.

You also do not need to amend anything in the default httpd.conf file from the standard WAMPServer defaults.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.