0

The following .htaccess was able to allow my symfony project domain to be served without app.php in the URL, as intended. The only issue is that it is breaking all other (non-symfony related) urls and causing an internal server error.

Right now, after deleting the .htaccess file from the server, all my domains work but the project tied to symfony must be accessed using app.php in URL ?

Is it possible to modify the below .htaccess to rewrite the symfony url to not require app.php in the URL while still allowing for all other URLs, not tied to symfony, to be accessed successfully?

Not sure this is needed, but assume the domain tied to symfony is www.apples.com.

Thanks in advance!

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^app.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>

Edit I also tried the following:

    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On

        # Explicitly disable rewriting for front controllers
        RewriteRule ^app.php - [L]

        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteCond %{REQUEST_FILENAME} !-d    

        # Change below before deploying to production
        RewriteRule ^(.*)$ app.php [QSA,L]
        DirectoryIndex index.php
</IfModule>
2
  • I don't see a problem with your htaccess file, are your other URLs also url rewrites? Commented Apr 30, 2014 at 14:54
  • Thanks for the reply. The problem with the first .htaccess is that it breaks all non-symfony related URLs. The problem with the second .htaccess is that all domains work but app.php must be included in the URL for the domain tied to the symfony project, so I'm back where I started, it is equivalent to deleting the .htaccess altogether. The other URLs are basic non-symfony (index.php) URLs. Commented Apr 30, 2014 at 14:57

2 Answers 2

1

Right after

RewriteCond %{REQUEST_FILENAME} !-f

add

RewriteCond %{REQUEST_FILENAME} !-d

and set DirectoryIndex to index.php

Sign up to request clarification or add additional context in comments.

7 Comments

I appreciate the help but I'm sorry to say, I spoke too soon, the app.php is still required in the URL after applying these changes.
Oh! Add [OR] to line checking file. And it should rewrite to app.php only if there are no requested file or directory.
sorry, I don't know what you mean, can you please show me an example?
I've edited my answer with "RewriteCond %{REQUEST_FILENAME} !-f [OR]"
Thanks for the reply. It seems to be working for the URL:) However, none of the css / images / or JS seems to be linking properly after this change to htaccess. Any ideas why this might be? I tried clearing the cache.
|
0

A bit late to this game but I just found an Apache directive that saves so much time and makes your htaccess cleaner. The only caveat is you must have Apache 2.2.16+. To have all urls except valid files (images, etc) use app.php as a front controller use the FallbackResource directive.

<Directory "/web/symfony-project">
    FallbackResource /app.php
</Directory>

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.