How to change the url in symfony using apache htaccess

Hi i have created one folder having three symfony application , then i have set the documentroot to that directory.
so when i access application i can see the url having web/app.php

http://example.com/app1/web/app.php/login

but i want to have the url like below
http://example.com/app1/login

how to set the url using htaccess in symfony , i already have htacess in web folder.

The problem with this setup is that a whole bunch of files that aren’t meant to be publicly accessible suddenly are. I think a better option is to point the documentroot elsewhere, maybe the standard /var/www, and use Alias to bring in each symfony app.

  Alias /app1 /path/to/app1/web
  <Directory "/path/to/app1/web">
    AllowOverride All
    Allow from All
  </Directory>

  # And so on for app2, app3

thank you it working…

now i can view the url like

http://domainname.com/app1/app.php/login/

i have htaccess on the web folder in symfony

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]

i want to hide app.php also in the url , how to rewrite in htaccess.

It looks fine as is. Seems like you should be able to type /app1/login into the address bar.

yes. i need to access like that, but when i type app1/login i got error

You’ll have to be a lot more specific than that. What error?

symfony error

No route found for “GET /app1/login”

i got works by bellow htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On  

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

Ahh. Well then, that means your htaccess is fine – the URL is being forwarded to the Symfony app – but something is wrong in the app itself. Maybe the routing, maybe you forgot to load your bundle… something like that.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.