如何编辑漂亮的URL的htaccess

时间:2013-12-04 22:59:08

标签: apache .htaccess mod-rewrite

我的网站如下:

| _index.php
|?_index.php页=约
| _articles {DIR}
  |?_articles / index.php页面= 2
  |?_articles / article_detail.php ID = 1个
| _events {DIR}
  |?_events / event_detail.php EVENT_ID = 1

如何让htaccess使用

这样的网址

mysite.com/about
mysite.com/articles/page/1/
mysite.com/articles/1/
mysite.com/events/1/

1 个答案:

答案 0 :(得分:1)

尝试

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^articles/([^/]+)/?$ /articles/article_detail.php?id=$1 [L]
RewriteRule ^articles/page/([^/]+)/?$ /articles/index.php?page=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/?$ /events/event_detail.php?id=$1 [L]