Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have this in my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

It rewrites both, http://www.site to http://site, and site to site/app.php I also want to rewrite site/index.php to site/app.php. How can I do it? When I request /index.php I get a 404 response.

I've tried to rename app_dev.php to index.php en my local host, but doesn't work. I've done the next change in .htaccess:

order allow,deny
allow from all
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  #   RewriteRule ^(.*)$ /app_dev.php [QSA,L]   #line deleted
  RewriteRule ^(.*)$ /index.php [QSA,L]         #line added
</IfModule>

and rename the file app_dev.php to index.php

share|improve this question

marked as duplicate by ThatGraemeGuy, Jenny D, Falcon Momot, MadHatter, dawud Sep 12 '13 at 15:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
It's not clear in your question what you want the URL bar to look like and which file you want to be processed. Could you also add what currently happens when you request /index.php? –  Ladadadada Sep 11 '13 at 8:49
    
Why not rename app.php to index.php? –  Pazi ツ Sep 11 '13 at 9:02
    
I don't know the reason why Symfony use this name, I'd prefer not to change what is working fine. Just want to do that rule. Is it possible? –  Manolo Sep 11 '13 at 9:06
    
yes I think you should use the permanent redirect for the URL. try that hope that should work for you. –  PratapSingh Sep 11 '13 at 13:19
    
How would you do it? With this? RewriteCond %{REQUEST_FILENAME} ^index\.php$ [NC] RewriteRule ^(.*)$ app.php [R=301,L]? –  Manolo Sep 11 '13 at 13:55
add comment

1 Answer 1

up vote 0 down vote accepted

How would you do it? With this? RewriteCond %{REQUEST_FILENAME} ^index.php$ [NC] RewriteRule ^(.*)$ app.php [R=301,L]?

No, something like this:

RewriteRule ^index.php$ / [R=301,L]

And you don't want to change the app.php line to index.php, assuming that you're getting a 404 because index.php isn't there, you don't want to be rewriting things to something that isn't there.

share|improve this answer
    
Ok, but where to add this line? I've tried it without success. Same response. –  Manolo Sep 12 '13 at 8:16
    
@ManoloSalsas to the top –  Jon Lin Sep 12 '13 at 8:39
    
Thanks! It works –  Manolo Sep 13 '13 at 10:03
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.