.htaccess sexy url rewrites

我只是一个虾纸丫 提交于 2019-12-12 01:14:17

问题


I want to get all my domains to rewrite and look good. for example:

example.com/blog.php?article=the-name-of-article to become example.com/blog/the-name-of-article

so i want the .php?article= to be changed into a /

my current .htaccess file looks like:

Options +FollowSymLinks -MultiViews
rewriteengine on

RewriteBase /

## Hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

but all that does is drop the .php

I have been searching around but I just want to hear how everyone accomplishes this so easily.


回答1:


RewriteRule ^blog/(.*)$ blog.php?article=$1 [QSA,L]


来源:https://stackoverflow.com/questions/16825252/htaccess-sexy-url-rewrites

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