我是否需要在 htaccess 中创建用于转换的文件夹

Do I need to create folders for conversion in htaccess

假设我要转换:

http://localhost/profile/view?q=James 

进入

http://localhost/profile/view/James 

问题是我必须为此创建一个名为 'view' 的新文件夹。有没有办法让我不需要为此创建文件夹?这个的 htaccess 规则是什么?

不,你不知道。您在 .htaccess 中使用 RewriteRule。这有效地将正则表达式与您的 URL 匹配,然后根据您的要求对其进行转换(很像:preg_replace)。

RewriteRule ^profile/view/([\w]+)/?$ path/to/profile/file.php?q= [L]

然后用户导航到:

http://www.website.com/profile/view/john

并且服务器将用户指向:

http://www.website.com/path/to/profile/file.php?q=john