views:

25

answers:

3

Is there any way i can use RewriteRule to show these links:

/articles_history.php

/articles_geography.php

as

/articles/history.html

/articles/geography.html

I created a .htacesss file on my root directory and would like to know if the above is possible by placing some kind of code in the .htaccess file.

+2  A: 
RewriteEngine On
RewriteRule /articles/(.+)\.html /articles_$1.php [L,QSA]
webdestroya
It's not workinghttp://localhost/yo/articles_history.php is still the same.
NegativeCrack
@NegativeCrack - Yes, the direct URL to the PHP file will still function just fine.
webdestroya
well, i actually want my browser to display:http://localhost/yo/articles_history.phpAShttp://localhost/yo/articles/history.htmlon the address bar. That's about it!I placed the .htaccess file in the "yo" folder.What exactly do I have to do now? Thanks for your help :)
NegativeCrack
@NegativeCrack - Now just go to `localhost/articles/history.html` You need to modify the RewriteRule if you want to have `/yo/` infront
webdestroya
A: 

Yes it is.

See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

In addition to RewriteRule, you also need to usually turn the rewrite engine on by the RewriteEngine directive.

antti.huima
A: 

Try this in your .htaccess:

RewriteEngine on
RewriteRule ^article/([^/]+)\.html$ articles_$1.php [L]

And for an arbitrary input:

RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)\.html$ $1_$2.php [L]
Gumbo