PHP - How to make pretty urls using mod_rewrite

不羁的心 提交于 2019-12-12 03:31:39

问题


I'm wondering how to make my URLs pretty and SEO friendly and also work with PHP code.

Currently everything works fine (for example example.com/test/ is fine and works).

However when I have error.php?id=404, I want it to go to /error/404/.

How do I do this?

My current .htaccess is...

RewriteCond /%{REQUEST_FILENAME} !-d
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php

Any help please?


回答1:


You can choose to let the framework handle it, or your can read more about mod_rewrite here

EDIT:

the underscore in url is not SEO friendly



来源:https://stackoverflow.com/questions/25496462/php-how-to-make-pretty-urls-using-mod-rewrite

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