htaccess:简化一个很长的Rewriterule

时间:2013-03-07 15:22:08

标签: mod-rewrite

我想写我的.htaccess文件,所以我有这个部分

(例如:http://www.mysite.com/tutorial/php/bydate/p7

RewriteRule ^(album|tutorial)/(.*)/(bydate|byuser|byrate|bypost)/(asc|desc)/p([0-9]+)$ $1.php?cat=$2&sort=$3&order=$4&p=$5 [QSA]
RewriteRule ^(album|tutorial)/(.*)/(bydate|byuser|byrate|bypost)/(asc|desc)/$ $1.php?cat=$2&sort=$3&order=$4 [QSA]
RewriteRule ^(album|tutorial)/(.*)/(bydate|byuser|byrate|bypost)/p([0-9]+)$ $1.php?cat=$2&sort=$3&p=$4 [QSA]
RewriteRule ^(album|tutorial)/(.*)/(bydate|byuser|byrate|bypost)/$ $1.php?cat=$2&sort=$3 [QSA]
RewriteRule ^(album|tutorial)/(.*)/(asc|desc)/p([0-9]+)$ $1.php?cat=$2&order=$3&p=$4 [QSA]
RewriteRule ^(album|tutorial)/(.*)/(asc|desc)/$ $1.php?cat=$2&order=$3 [QSA]
RewriteRule ^(album|tutorial)/(.*)/p([0-9]+)$ $1.php?cat=$2&p=$3 [QSA]
RewriteRule ^(album|tutorial)/(.*)/$ $1.php?cat=$2 [QSA]

我的问题是:

1-是否更好地使用它?或者足够

RewriteRule ^(album|tutorial)/(.*)/$ $1.php?cat=$2 [QSA]

(例如:http://www.mysite/tutorial/php/?sort=bydate&order=desc&p=2

我处理我的php文件中的参数?

2-如果我想使用第一部分,是否可以简化它?

1 个答案:

答案 0 :(得分:0)

处理PHP文件中的参数始终是更好的方法。否则你会有一个带有一百个RewriteRules的.htaccess文件...

只需查看Wordpress .htaccess文件:

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

将所有内容(现有文件和目录除外)重定向到index.php文件。 这是所有的了。