HI,
I need help in .htaccess to hide php extension.

if someone request www.mysite.com/profilename , then profile should be open of the particular person. Please help me in this, how can i accomplished this using .htaccess?.

Your help in this will be highly appreciated.

Thankyou,
syed.

Recommended Answers

All 12 Replies

Trying placing the following in your htaccess file and place the htaccess file in the same folder as the homepage:

RewriteEngine On
RewriteRule ^([^.]+[^/])$ $1.php

Also note that when linking to directories such as the hompage you may need a forward slash at the end.

hi there thank you for you response. I put the code that you told me in .htaccess file but i got the server 500 error.

following is a error i got.
" The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster. "

how can i get rid of it.

please reply.

I've tested the htaccess code I've posted and it seems to work perfectly for me so perhaps the rewrite module isn't correctly enabled as in the past, I have encountered that error while trying to enable the rewrite module.

Do you have mod_rewrite installed?
What OS platform and apache version are you using?

I don't really know if mod_rewrite is installed? Please guide me how to install it. I think this will solve the problem. I am using windows XP professional and XAMPP version is 1.6.2.

Thank you.

please reply.

its not your local pc, thats insignificant, though its good if the development system is configured the same as the real host
mod_rewrite needs to be installed on the host, the server the site will be running on the www
test the .htaccess file given on the web server to see if the host has enabled mod_rewrite
if not enabled you may have to query your hosting company to have it enabled, most hosts do not allow you(me/them) to recompile the OS, for very obvious reasons.

Check your httpd.conf file in the apache installation. Search for mod_rewrite and uncomment the line. Then you should be able to use it. Xammp has mod_rewrite disabled by default

In case you need more info on how to enable it with xampp, I shall post more detailed instructions. First as a backup, copy the file located at C:\xampp\apache\conf\httpd.conf to another location in case you do a few things wrong. After copying that file, open the original at C:\xampp\apache\conf\httpd.conf then uncomment line 118 which should contain the following data:

#LoadModule rewrite_module modules/mod_rewrite.so

To uncomment it, just remove the hash at the beginning. Then save and close the file. After that, do a reboot and .htaccess files should then be enabled.

put this in ur htaccess file

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

I use this in my htaccess

<Files ~ "^[^\.]+$">
       ForceType application/x-httpd-php5
</Files>

It will treat any file without slash and dot as a php5 file.

RewriteEngine On
RewriteRule ^(.*)$ index.php?req=preview&pro_name=$1

That should (probably) do the trick. You should create a good structure for your URLs if you want to have URLs for anything else than pro_names.

/person/Rehman1234
/blabla/somethingelse

RewriteRule ^person/(.*)$ index.php?req=preview&pro_name=$1
RewriteRule ^blabla/(.*)$ index.php?req=blabla&value=$1

Please see http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html for more info on how mod_rewrite works

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.