是否可以将域分配给动态创建的“文件夹”


is it possible to assign a domain to a "folder" created dynamically?

我正在开发一项服务,我需要为动态创建的页面提供不同的域,例如,我将有这样的东西:

example.net/?client=hello

我认为,使用 htaccess 我可以实现这一目标:

example.net/hello

是否可以将域指向该"文件夹"?

我不太确定你说的point a domain to that folder是什么意思.但是如果你想重写example.net/hello example.net/index.php?client=hello你可以这样做:

# check so it's not a file
RewriteCond %{REQUEST_FILENAME} !-f
# check so it's not a directory
RewriteCond %{REQUEST_FILENAME} !=d
# do we have a client name in the url?
# valid names are not case sensitive and containing letters between a-z
Rewritecond %{REQUEST_URI} ^([a-zA-Z]+)$
# pass the client name to index.php 
RewriteRule ^(.*)$ index.php?client=$1 [L,QSA]

相反,如果您想将index.php?client=hello重写到名为hello的现有文件夹,这应该可以工作:

# check so it's not a directory
RewriteCond %{REQUEST_FILENAME} !=d
# check so we have a valid query string
RewriteCond %{QUERY_STRING} ^client=([a-zA-Z]+)$
# check so the client directory really exists
RewriteCond %1 -d
# rewrite to client folder and strip of the query string 
RewriteRule ^index'.php$ %1? [L]