PHP - How to make pretty urls using mod_rewrite

2019-09-05 23:58发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-09-06 00:25

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

查看更多
登录 后发表回答