1

All the htaccess rules in my Webproject do their job. However, I wonder if there is any way around to write a single rule using REGEX instead of hard-coding them as shown below. I couldn't find question/answers on SO that address the need mentioned here. Thanks for any advice or help.

RewriteEngine on

RewriteRule ^index                               index.php 
RewriteRule ^about-us                            about-us.php
RewriteRule ^web-application-development         web-application-development.php
RewriteRule ^mobile-application-development      mobile-application-development.php
RewriteRule ^offshoring                          offshoring.php
RewriteRule ^internet-marketing                  internet-marketing.php
RewriteRule ^careers                             careers.php
RewriteRule ^blog                                blog.php
RewriteRule ^contact-us                          contact-us.php

I am looking for a single rule involving REGEX that does the job that all the rules above do when put together.

CodeForGood
  • 767
  • 7
  • 30

1 Answers1

1

You can use this single rule to rewrite your .php requests

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]

Alternatively ,you could enable multivies to access files without extensions, add the following line to your htaccess.

Options +Multiviews
Amit Verma
  • 40,709
  • 21
  • 93
  • 115