RewriteRule question

我与影子孤独终老i 提交于 2019-12-11 23:02:19

问题


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.


回答1:


RewriteEngine On
RewriteRule /articles/(.+)\.html /articles_$1.php [L,QSA]



回答2:


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.




回答3:


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]


来源:https://stackoverflow.com/questions/2841502/rewriterule-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!