0

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?

11
Contributors
33
Replies
41
Views
5 Years
Discussion Span
Last Post by vizz
0

Try this:

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

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

Edited by phorce

0

It is giving 500 Internal Server Error

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

0

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?

0

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

0

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.

0

but without that htaccess is not working on server

Need help

0
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

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

Edited by coreyavis: Added spaces

0

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

Thanks

But,
It's Not working

0

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.

0

Try this:

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

mod_rewrite is not enabled

thanks.

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

0

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

0

Try this in your htaccess:

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

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?

0

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

0

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.

1

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.

-1

.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.

Votes + Comments
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

0

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.

0

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?

0

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

Edited by ko ko: Wrong spelling

0

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?

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.