0

I have seen quite a few answers on how to redirect many URLs so that any .php extensions are removed, but this has been causing some troubles for me with conflicts.

RewriteRule ^quote/([a-zA-Z0-9]+)/$ index.php?id=$1 RewriteRule ^quote/([a-zA-Z0-9]+)$ index.php?id=$1 

I already am redirecting /quotes/1 /quotes/2 etc to /index.php?id=1 and /index.php?id=2 etc. But what I really want to do is simply match /random/ and have it point to /random.php and none of the existing answers seem to be that specific.

Thanks.

1
  • So you handle all of your business logic in index.php like if isset($_GET['id']){...}? Well, what you really should focus on now is to any popular php framework. This is a very basic thing called Routing and Controllers Commented Oct 11, 2014 at 1:08

1 Answer 1

1

To remove the .php extension with .htaccess use this:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L] 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this seems to work well for /random however is there any way to get it working for /random/ with the trailing slash as well?
@Rizier123 don't you want to capture anything for $1 to work? And it is a good idea to add check for the directory RewriteCond %{REQUEST_FILENAME} !-d

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.