且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

性感的.htaccess URL重写

更新时间:2023-11-26 23:28:34

 重写规则^博客/(.*)$ blog.php的?文章= $ 1 [QSA,L]
 

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.

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