Hi, can i ask some help,is it possible to remove the extension php(.php) in the url ?
I want that the url looks like this
it removes the .php extension in the contact.
can you help me please how to achieve on this
Thank you in advance.
Hi, can i ask some help,is it possible to remove the extension php(.php) in the url ?
I want that the url looks like this
it removes the .php extension in the contact.
can you help me please how to achieve on this
Thank you in advance.
create a folder called contact and rename your file to index.php
I mean to my every page, i want to remove the .php extension
etc…
Or create .htaccess file in the root of your website and place this code inside:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ $1.php [L]
If you already have .htaccess file, just append this code to it.
This will basically rewrite everything to the same thing plus “.php” so if you request yourwebsite.com/contact it will open yourwebsite.com/contact.php
The regex in this code doesn’t match dot (.) so ordinary files (with extension) shouldn’t be rewritten, e.g. if you request yourwebsite.com/contact.css it will serve it correctly, it won’t load yourwebsite.com/contact.css.php
Note: This is .htaccess rule for Apache server with mod_rewrite support. It may work on other servers that support similar type of URI rewriting.
then you need to do it either with a cms so everything is filtered through the index file or in the htaccess file something like
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^GET\\ (.*)\\.php\\ HTTP
RewriteRule (.*)\\.php$ $1 [R=301]
please note I am not very good at redirects on the htaccess file so read more on that and or ask you question in a specific forum for that
Hi, I am not familiar with .htaccess how to use this ?
A .htaccess file is a special file with instructions for the web server (apache).
You can tell it to do specific things like redirect certain requests.
For this instance the easiest way is to create a file called .htaccess and put the following in it
Options -MultiViews +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\\.php -f
RewriteRule ^(.+)$ $1.php
That will rewrite all requests that have a .php counterpart to that .php counterpart, i.e., /contact to /contact.php etc, but if and only if that .php file exists.
HI ScallioXTX,
Thank you for the reply…Okay i will try this,what if i am working on the local do i need to configure my apatche?..
Thank you in advance.
Out of the box .htaccess don’t work on apache. To enable them, follow the instructions described under the header “Server Setup” on this page: http://datakoncepts.com/seo
Thank you so much for the reply, Okay i’ll give a try on this, i will write back to you if i get in trouble. thank you.
Rémon,
(.*) can be null which would redirect to .php - not a pretty picture. IMHO, always require something, i.e., + rather than *.
“Out of the box,” .htaccess does work. It’s mod_rewrite which, by default, does not work (must be enabled).
Thanks for the referral, anyway, as the SEO page should clear it all up for him!
Regards,
DK
Indeed, that’s what the RewriteCond %{REQUEST_FILENAME}\\.php -f
is there for; to prevent invalid requests like the one you’re proposing
That said, (.+) would indeed be better than (.*) in this case. I’ll amend my earlier post.
Ah yes, you’re right. It’s been a while since I’ve set up an apache server from scratch and I tend to forget these things