使用.htaccess重写具有ID和文件名的URL


Using .htaccess to Rewrite URLs with ID and Filename

我正试图用.htaccess重写一个URL,但经过数小时的搜索,我还是找不到答案。而且,我的正则表达式技能没有那么好也于事无补。。。

我的URL的基本格式是:http://mysite.com/article.php?id=1

我想有一个这样的网址直接在那里:http://mysite.com/article/1/made-up-irrelevant-title-slug

问题是,我希望article是一个变量,这样它就可以被更改为page,并从http://mysite.com/page/1/made-up-page-name直接指向类似的内容:http://mysite.com/page.php?id=1

如果有人知道这是怎么写的,我将不胜感激!

# Turn on Rewrites
RewriteEngine on
# Do not rewrite existing files, directories, or symlinks.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# Rewrite /COMPONENT/ID/TITLE -> COMPONENT.php?id=ID
RewriteRule ^([^/]+)/('d+)/.*$ $1.php?id=$2 [L]