让我们认为我在htaccess中有这样的代码:
RewriteRule ^admin/registration/?$ admin/qeyd.php [NC,L]
RewriteRule ^admin/login/?$ admin/login.php [NC,L]
RewriteRule ^admin/profile/?$ admin/profile.php [NC,L]
但我想为“admin”定义一个变量,并按如下方式编写: admin_directory_variable = custom_name
RewriteRule ^custom_name/registration/?$ admin/qeyd.php [NC,L]
RewriteRule ^custom_name/login/?$ admin/login.php [NC,L]
RewriteRule ^custom_name/profile/?$ admin/profile.php [NC,L]
我该怎么做?
答案 0 :(得分:2)
创建admin/.htaccess
文件并使用以下规则:
RewriteEngine On
RewriteBase /admin/
RewriteRule ^registration/?$ qeyd.php [NC,L]
RewriteRule ^(login|profile)/?$ $1.php [NC,L]
答案 1 :(得分:0)
Apache 2.4具有 Define 关键字,您可以这样使用:
Define name value
并使用如下:
DocumentRoot ${name}
不幸的是,它无法在.htaccess文件中使用。见Apache 2.4 documentation