此固定链接/友好网址:
http://anything.com/ok
应该提供此路径/网址:
http://anything.com/path/to/page/dir1/dir2/page.php?parameter=ok
这有效,但这是硬编码的。需要动态方法。 dir1可以是任何东西,dir2可以是任何东西,参数=之后的文本可以是任何东西。
RewriteRule ^ok/{0,1}$ path/to/page/dir1/dir2/page.php?parameter=ok [QSA,L]
以下是我尝试过的一些没有成功的事情。
#RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?parameter=$1
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /page\.php\?parameter=([^\&\ ]+)
#RewriteRule ^/?page\.php$ /page/%1? [L,R=301]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^path/to/page/([^/]+)/([^/]+)$ page.php?parameter=$1 [L]
#RewriteRule ^page/{0,1}$ http://%4/path/to/page/%3/%2/page.php?parameter=%1 [QSA,L]
#RewriteRule ^$4/{0,1} http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
#RewriteRule ^page/{0,1}$ http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
#RewriteRule ^page/{0,1}$ http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
#RewriteRule ^$ http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
#RewriteRule ^$4 http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
#RewriteRule ^$4 http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
#RewriteRule ^/{0,1}$ http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
#RewriteRule ^/{0,1}$ http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
#RewriteRule ^/{0,1}$4 http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
#RewriteRule ^/$4 http://%1/path/to/page/%2/%3/page.php?parameter=%4 [QSA,L]
#RewriteRule ^/$4 http://$1/path/to/page/$2/$3/page.php?parameter=$4 [QSA,L]
修改
这适用于随机参数。现在我只需要知道如何在url中间随机添加两个文件夹。
RewriteRule ^([^/.]+)/?$ path/to/page/dir1/dir2/page.php?parameter=$1 [L]
随机2个文件夹的示例:
/admin/11-blah/
/development/546-whatever/
/abc-company/46208-name-of-project/
可以是那两个目录名称。除了破折号之外没有特殊字符。字母数字和破折号。
编辑2:
我是否理解友好重写必须包含完整脏网址的所有动态元素?
我让这个工作:
RewriteRule ^([^/.]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ path/to/page/$1/$2/page.php?parameter=$3 [L]
这意味着干净的网址将如下所示:
http://anything.com/admin/11-blah/ok
但是没有办法让它看起来像这样?:
http://anything.com/ok