1

i have a file named Show.php

i want to remove .php extension of this, and if someone requested /Show.php, redirect him to without .php extension Page.

This is my htaccess but it does not redirect user to without extension page.

RewriteCond %{REQUEST_URI} ^Show\.php$
RewriteRule ^Show\.php$ ./Show [R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^Show$ ./Show.php [L]

1 Answer 1

1

REQUEST_URI, unlike the RewriteRule expression, begins with a leading / but your expression begins with ^Show. Simply adding the leading slash should do the job. Everything else looks correct.

RewriteCond %{REQUEST_URI} ^/Show\.php$
#-------------------------^^^^^
RewriteRule ^Show\.php$ Show [R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#Rewrite to Show.php rather than ./Show.php
RewriteRule ^Show$ Show.php [L]
Sign up to request clarification or add additional context in comments.

2 Comments

It not worked. /Show.php not redirected to /Show. i'm sure my first RewriteCond is wrong. but i don't know how to fix it.
@HosseiN Does the request also have a query string as /Show.php?thing=123 ? If so, the RewriteCond should not have a $ anchor

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.