Lukas Lukac
Lukas Lukac

Reputation: 8346

symfony2 .htaccess hide app.php from url

I am trying to hide the app.php from url

I have:

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

Which works okay.. but when user visit

domain.com/app.php/Home/

than the url is still

domain.com/app.php/Home/

and i want have only

domain.com/Home

How to solve it?

I tried:

#RewriteCond %{THE_REQUEST} ^.*/app.php
#RewriteRule ^(.*)app.php/(.*)?$ /$2 [R=301,L]

Which work as i need but when i do some action dynamic jquery ajax action i get error 405.

Upvotes: 0

Views: 2665

Answers (3)

Wirone
Wirone

Reputation: 3373

Seems like you don't have mod_rewrite enabled. You have to do on your machine:

  • sudo a2enmod rewrite (or enable module in other way if you don't have a2enmod)
  • service apache2 restart or /etc/init.d/apache2 restart

Next, you have to set AllowOverride All in your vhost config to be sure URLs will be properly catched by Symfony's web/.htaccess.


Additional info: in Symfony's web/.htaccess:

<IfModule !mod_rewrite.c> <IfModule mod_alias.c> # When mod_rewrite is not available, we instruct a temporary redirect of # the start page to the front controller explicitly so that the website # and the generated links can still be used. RedirectMatch 302 ^/$ /app.php/ # RedirectTemp cannot be used instead </IfModule> </IfModule>

If mod_rewrite is not enabled, apache uses mod_alias to pass all requests through app.php. So if you enter root URL of your domain and you're redirected to app.php it's probably because of mod_rewrite.

Upvotes: 2

Lukas Lukac
Lukas Lukac

Reputation: 8346

I wrote something like this but i am not sure if its good solution?

RewriteCond %{THE_REQUEST} ^.*/app.php 
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^(.*)app.php/(.*)?$ /$2 [R=301,L]

Upvotes: 0

Nicolai Fr&#246;hlich
Nicolai Fr&#246;hlich

Reputation: 52473

The solution to your problem is described here.

<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]
</IfModule>

Upvotes: -1

Related Questions