.htaccess 如何创建此动态htaccess重写规则?

.htaccess 如何创建此动态htaccess重写规则?,.htaccess,.htaccess,此永久链接/友好url: http://anything.com/ok 应为以下路径/url提供服务: http://anything.com/path/to/page/dir1/dir2/page.php?parameter=ok 这是可行的,但这是硬编码的。需要动态的方法。dir1可以是任何内容,dir2可以是任何内容,parameter=后面的文本可以是任何内容 RewriteRule ^ok/{0,1}$ path/to/page/dir1/dir2/page.php?parame

此永久链接/友好url:

http://anything.com/ok
应为以下路径/url提供服务:

http://anything.com/path/to/page/dir1/dir2/page.php?parameter=ok
这是可行的,但这是硬编码的。需要动态的方法。dir1可以是任何内容,dir2可以是任何内容,parameter=后面的文本可以是任何内容

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:

我是否理解友好重写必须包含完整脏url的所有动态元素

我让这个工作:

RewriteRule ^([^/.]+)/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ path/to/page/$1/$2/page.php?parameter=$3 [L]
这意味着干净的url将如下所示:

http://anything.com/admin/11-blah/ok
但是没有办法让它看起来像这样

http://anything.com/ok

所以基于什么应该是dir1和/或dir2动态?这两个目录可以是随机的。第一个是公司名称,第二个是项目名称,thing after参数指定访问页面的用户。这三件事都是随机的。许多不同的公司,每个公司都有许多不同的项目,每个项目都有大量的用户。你的问题就像你想从访问
http://anything.com/ok
要重定向到
http://anything.com/path/to/page///page.php?parameter=ok
(这没有意义,因为您需要在某个地方找到您的
)…所以我猜你想换一种方式吗?你的问题真的不清楚。短url应该放在浏览器地址栏中,但应该提供物理上存在的长url中的文件。整个路径在物理上存在。指向参数的所有文件夹。需要以某种方式制作短url或永久链接或其他任何内容rminology是。有成千上万的组合或url,正确的方法是不要在htaccess中创建数千行,所以寻求更好的方法。