I have hosting and domain with https://www.znetlive.in (with Apache version 2.2.21) suppose www.abc.com

I want to rewrite urls.(Which is not working in anyways)

http://www.abc.com/index.php for this http://www.abc.com

http://www.abc.com/about.php for this http://www.abc.com/about

http://www.abc.com/portfolio.php for this http://www.abc.com/portfolio

http://www.abc.com/contact.php for this http://www.abc.com/contact

I have tried all possible ways but it is not working. Can Anybody write code for me?

Try this:

(save it as .htaccess) and make sure it's in the correct folder (like localhost, www etc.)

RewriteEngine  on
RewriteRule ^(.*)$ $1.php

It is giving 500 Internal Server Error

RewriteEngine on
RewriteRule ^(.*)$ $1.php

I found this
Which is not working for me, but what I want it is exactly.

It is not working on localhost as well as on server, can anyone help?

alright I found another way and it worked. Just removed .php extension form all pages and it's working.
Another problem is, how to hide index from www.abc.com/index

Member Avatar for diafol

alright I found another way and it worked. Just removed .php extension form all pages and it's working.

Did you change the physical filenames to no extension??

If so, that's not the way to do it.

but without that htaccess is not working on server

Need help

FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [R=301,L]

# Redirect to non.php extension
RewriteCond %{THE_REQUEST} ^GET\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$  $1 [R=301,L] 

## Rewrite Rules ##
RewriteRule ^([0-9-a-z-A-Z-_]+)/?$ goto.php?id=$1 [L]
RewriteRule ^account/(.*)$  $1.php [L]

copy above code in .htaccess in your public_html or home folder.

It will remove all extension.

All the best. If its work for you, please vote and mark this as a sloved

thanks, but

Server error! It's not working

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

Thanks

But,
It's Not working

Can you be more specific?

without removing .php extension any code in this thread does not work. Some gives 500 Internal Server Error. And above code does not work also it does not give any error.

Try this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

500 Internal Server Error

Perhaps mod_rewrite is not enabled. Check with your host.

mod_rewrite is not enabled

thanks.

Now it is enabled by hosting provider, still codes are not working

I am using following code with removing file extension (.php),

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

Just replace htm with your file extension which you want to hide, eg: php, html, aspx, jsp etc.

Without removing .php codes are not working

Try this in your htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteRule ^(.*)\.html$ $1.php
Member Avatar for diafol

Just a thought. I used to have problems with FTP years ago with uploading .htaccess files. How about you upload the file as htaccess.txt (plain text file) and then rename it to .htaccess once it's on the server?

Just a thought. I used to have problems with FTP years ago with uploading .htaccess files. How about you upload the file as htaccess.txt (plain text file) and then rename it to .htaccess once it's on the server?

tried this way but not working. still problem

How about the simplest rewrite:

RewriteEngine On
RewriteRule ^test$ index.php [R=302,NC,L]

If you go to test will it redirect to index.php ? If not even that is working, contact your host to get a working example first.

Try. This one is working on my localhost.

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

Add below at the bottom of your htaccess to rewrite if theres is no rewrite rule for request, and it'll rewrite to index.htm. You can change index.htm to anything (index.php/asp/jsp) you like to rewrite if rewrite failed.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^(.*) [NC]
RewriteRule ^(.*)$ index.htm

BTW, @diafol, what kind of problem with FTP with uploading htaccess file ? I just wondering to know coz I'm very OK with htaccess and FTP.

.htaccess files should be uploaded as binary. If the code I gave you above doesn't work, then you have something configured wrong on your server.

commented: It's text file and must upload as ASCII or text mode. +0

my hosting service providers said "You have coding problem".

But I don't think so. And I already have enough help and solutions in this thread as well as I have tried all possible ways of coding.

I want to check, what service provider said, is true or not.

Can anybody provide proper code for following?

http://www.abc.com/index.php convert to http://www.abc.com

http://www.abc.com/about.php convert to http://www.abc.com/about

http://www.abc.com/portfolio.php convert to http://www.abc.com/work

http://www.abc.com/contact.php convert to http://www.abc.com/contact

Try. This one is working on my localhost.

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

This can server what you actaully need. Anyway, have you already check what @pritaeas said.

How about the simplest rewrite:
RewriteEngine On
RewriteRule ^test$ index.php [R=302,NC,L]
If you go to test will it redirect to index.php ? If not even that is working, contact your host to get a working example first.

I have checked all codes and all are not working on server
One more thing,
in file httpd.conf

which AllowOverride None need to be changed to AllowOverride All ?

what are requirements regarding httpd.conf to run above code for rewriting url?

Perhaps, you need to have AllowOverride if your hosting provider set by default AllowOverride None You can see details on Apache web site here.

As pritaeas says, have you tried simple htaccess rule?? like below?

# This allows you to redirect your entire website to any other domain
Redirect 301 / http://www.google.com/

First of all check if htaccess is working in your server or not?

redirect is ok (only redirection works on server). It works but file extension is problem. it's not working anyways

I think problem is about mod_rewrite on server but no proper support form hosting service provider they are saying continuously coding problem (I don't think so) .

Can anybody write code for me?

http://www.abc.com/index.php convert to http://www.abc.com

http://www.abc.com/about.php convert to http://www.abc.com/about

http://www.abc.com/portfolio.php convert to http://www.abc.com/work

http://www.abc.com/contact.php convert to http://www.abc.com/contact

please help

What are your htaccess currently using ? Post all inside your htaccess. Also, check your apache and phpinfo with 'phpinfo()' within your PHP file. Especially see Loaded Modules to check which modules are being loaded. And post some infos what you gets.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.