问题描述
RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /?paramOne=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /?paramOne=$1¶mTwo=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /?paramOne=$1¶mTwo=$2¶mThree=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /?paramOne=$1¶mTwo=$2¶mThree=$3¶mFour=$4 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /?paramOne=$1¶mTwo=$2¶mThree=$3¶mFour=$4¶mFive=$5 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /?paramOne=$1¶mTwo=$2¶mThree=$3¶mFour=$4¶mFive=$5¶mSix=$6 [L]
原因是有多个相同的东西,这样我就不必填写所有的 url 参数,
我怎样才能解决这个问题?
谢谢!
解决方法
你所有的规则都使用相同的模式,这是不对的。
应该这样写:
RewriteEngine On
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ ?paramOne=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ ?paramOne=$1¶mTwo=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]=)/?$ ?paramOne=$1¶mTwo=$2¶mThree=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ ?paramOne=$1¶mTwo=$2¶mThree=$3¶mFour=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ ?paramOne=$1¶mTwo=$2¶mThree=$3¶mFour=$4¶mFive=$5 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ ?paramOne=$1¶mTwo=$2¶mThree=$3¶mFour=$4¶mFive=$5¶mSix=$6 [L,QSA]