# Redirect no file extension to .php



## SVTCobraLTD (Nov 18, 2007)

I have done this before but cannot find my old htaccess file. I have googled and cannot seem to come up with the correct code so that when a user visits www.mysite.com/page it will not give a 404 error. I want it to automatically redirect to the same page but .php. There are lots of pages so I dont want to enter the code for each page. Thoughts?


----------



## Squashman (Apr 4, 2003)

Is page a directory or php file?
Could you give us an example of the input and desired redirect output.


----------



## SVTCobraLTD (Nov 18, 2007)

Its a php page. If your browse to www.mysite.com/testpage I get a 404 error. However if you do www.mysite.com/testpage.php it will load the page as it should.


----------



## Squashman (Apr 4, 2003)

So you want to append *.php* onto every link that comes to your site. Are there no directories where you would want the default document to be displayed should they go to a valid subdirectory?


----------



## namenotfound (Apr 30, 2005)

SVTCobraLTD said:


> There are lots of pages so I dont want to enter the code for each page. Thoughts?


Alright it can be a pain, I find coding each page individually provides more flexibility and control over how your site functions. You can just throw some code in the .htaccess file that will add *.php* to the end of all urls, but that might not always be what you want if say the page is actually a directory or if the file uploaded has a different extension other than .php

Maybe it's just be, but I like having that extra control that comes with coding each page one at a time in the .htaccess file. For example


```
RewriteRule ^testpage?$ testpage.php
```
That will turn mysite.com/testpage into mysite.com/testpage.php

If you'd also like the ability for it to see the page if someone adds an extra slash, you can do that too


```
RewriteRule ^testpage(/)?$ testpage.php
```
That will turn mysite.com/testpage and mysite.com/testpage/ into mysite.com/testpage.php


----------

