带有 .htaccess 的动态子域
阅读此处的帖子后,我能够使用 .htaccess 文件创建动态子域
RewriteCond %{HTTP_HOST} !^www.sitename.com
RewriteCond %{HTTP_HOST} ([^.]+).sitename.com
RewriteRule ^(.*)$ /sitepath/subdomain.php?str1=%1
为此,我创建了一个带有一个变量的 subdomain.php 文件,即 str1(子域的名称)。现在要实现以下结果
- subdomain.sitename.com (已完成)
- subdomain.sitename.com/str2/ (在查询字符串中传递第二个变量)
- subdomian.sitename.com/str2/str3/ (第二个和第三个变量)
- if任何人在地址栏中手动添加一个变量都应该被重定向到 404 错误页面 (subdomain.sitename.com/str2/str3/str4/)
提前致谢。
After reading posts here i was able to create dynamic subdomains with .htaccess file
RewriteCond %{HTTP_HOST} !^www.sitename.com
RewriteCond %{HTTP_HOST} ([^.]+).sitename.com
RewriteRule ^(.*)$ /sitepath/subdomain.php?str1=%1
for this i had created one subdomain.php file with one variable i.e., str1 (name of the subdomain). Now what to achieve following results
- subdomain.sitename.com (this is done)
- subdomain.sitename.com/str2/ (pass second variable in the query string)
- subdomian.sitename.com/str2/str3/ (second and third variable)
- if anybody add one more variable in the address bar manually should be redirected to 404 error page (subdomain.sitename.com/str2/str3/str4/)
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 RewriteConds 行可能首先仅适用于一个特定的虚拟主机。
It is possible that your RewriteConds lines only apply to one specific vhost in the first place.