0

Hello guys I am practicing how to change the .php extention in my php pages, no luck yet. I am using WAMP 3.1.0 on a 64bit here the software versions in the WAMP

  • Apache Version:2.4.27
  • PHP Version:5.6.31 Server Software:Apache/2.4.27 (Win64)
  • PHP/5.6.31 - Port defined for Apache: 80

I have the rewrite_module turned on on the httpd.conf file I have this string "LoadModule rewrite_module modules/mod_rewrite.so" commented out and changed AllowOverride None to AllowOverride ALL.

Below is the screenshot of my folder structure

enter image description here

here is my index.php file screenshot

enter image description here

here is my htaccss screenshot

enter image description here

1
  • 3
    Please don't post screenshots of code. Paste your code directly into the question. Commented May 16, 2019 at 7:29

1 Answer 1

1

You may try this to remove .php extensions completely from your file and to avoid infinite loop :

RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ $1.php [NC,L] 

This code will work in Root/.htaccess, Be sure to change the RewriteBase if you want to place this to a htaccess file in sub directory.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks very much it worked but the code is difficult for me to understand.
Yes I agree. .htaccess rules are majorly regular expression which works with the parameters and conditions mentioned for request or filenames.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.