View Full Version : url rewriting . htacess [ask]
likon
05-01-2008, 02:38 AM
hi guys..
how to rewrite the ".php" into "?" or even dont show it ?
like example.com/index.php to become example.com/index
thanks
abduraooft
05-01-2008, 07:58 AM
I think you are asking the reverse ;), ie. even if we give the links like /index, /about etc and access them, the server should serve /index.php and /about.php.
If this is what you've asked, then
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
should work! :)
you could also use in the .htaccess
RewriteEngine On
RewriteRule !\.{css|jpg|png|gif}$ index.php
And in your index.php file, have a script which grabs the entire url ($_SERVER['REQUEST_URI']), replace /index.php/ with "" [str_replace()];
and then check for the page.
likon
05-01-2008, 10:04 PM
I think you are asking the reverse , ie. even if we give the links like /index, /about etc and access them, the server should serve /index.php and /about.php.
would it still how the word ".php" after in the address bar ?
my purpose is to remove the word ".php"
sorry. havent tested yet, kinda researching.
ruby on rails dont have extension like .php. so .. i want it to be like that.
example.com/nodotphpbehindthissentence
aedrin
05-01-2008, 10:28 PM
If all you care about is that, you can simply use your server's default file settings.
When you request a URL:
www.example.com/info/
The server will look for a few defaults in the folder info/
www.example.com/info/index.htm
www.example.com/info/index.html
www.example.com/info/index.php
This means your URL will work without the index.php, it also works with a query string:
www.example.com/info/?page=something
Will result in the server trying:
www.example.com/info/index.php?page=something
Don't bother with mod_rewrite unless you really need it.
RewriteRule !\.{css|jpg|png|gif}$ index.php
That's silly by the way, what about javascript files? Sure, you can add the extension, but it requires you to modify this file every time you add a new file type. Will you remember? I'm not so sure you can say that you will 100%. Meaning it's a failure point.
The better solution is the one provided by abduraooft.
What you are looking for is called MultiViews (http://httpd.apache.org/docs/2.2/content-negotiation.html#multiviews). Available in all current Apache versions.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.