Possible Duplicate:
Remove .php extension with .htaccess
I want to make all my website URLs, myurl/webpageexamples.php
, to be renamed to its non-extension version myurl/webpageexamples
, if possible in .htaccess and at the same time redirect all traffic from myurl/webpageexamples.php
to the new myurl/webpageexamples
.
I have found several to redirect from PHP to non-PHP like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
What I have:
myurl/webpageexamples.php
What I want:
myurl/webpageexamples
I would like to have the SEO score transferred to new myurl/webpageexamples
.
The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client). The 'header_value' in the function is used to store the header string. The 'replace_value' parameter stores the value that needs to be replaced.
To set a permanent PHP redirect, you can use the status code 301. Because this code indicates an indefinite redirection, the browser automatically redirects the user using the old URL to the new page address.
Redirection from one page to another in PHP is commonly achieved using the following two ways: Using Header Function in PHP: The header() function is an inbuilt function in PHP which is used to send the raw HTTP (Hyper Text Transfer Protocol) header to the client.
You want to make sure you are redirecting if the actual request is for a php page, and internally rewriting when the URI is missing the php:
RewriteEngine On
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With