0

I want to redirect my website URLs with .php extension currently all URLs are opening with and without .php

example

https://www.ranglerz.com/about.php
https://www.ranglerz.com/about

The both URLs are working now but I want if user open https://www.ranglerz.com/about it will redirect to https://www.ranglerz.com/about.php

here is my htaccess code

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ $1.php [NC,L]

I've tried all solutions that provided in different threads but nothing is working with this problem.

1
  • If you want to redirect the user, then you need to do that. Currently you only rewrite the requests internally. Please read the documentation of apaches rewriting module: httpd.apache.org/docs/current/mod/mod_rewrite.html Commented Sep 28, 2017 at 14:31

1 Answer 1

2

You can use:

Options -MultiViews

# Redirect to .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [R=301,L]
Sign up to request clarification or add additional context in comments.

4 Comments

using both conditions. I'm only getting URLs without extension
but i can use it without .php extension. Thanks for it
can you please guide me the purpose of "Options -MultiViews" line in this condition
The Apache docs on mod_negotiation, describes what the Multiviews Option does, when enabled (what you should avoid in your case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.