我读了这个.htaccess 重写以将根 URL 重定向到子目录 https://stackoverflow.com/questions/990392/htacces-rewrite-to-redirect-root-url-to-subdirectory我正在努力实现同样的目标。
得票最多的解决方案是:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ store [L]
现在看评论,感觉效果还不错。
问题是我不想对任何路径进行硬编码(如上面“www.example.com”提供的那样)。我想要我的.htaccess
inside projectname/
重定向到projectname/public/
不管真正的服务器主机是什么。所以如果我把projectname/
在根服务器内www.pinco.com
它重定向到www.pinco.com/projectname/public/
但它表明www.pinco.com/projectname/
.
我怎样才能做到这一点?
您找到的示例实际上在做两件不同的事情。
# This is actually just redirecting all http://example.com/somepage/
# to http://www.example.com/somepage/, to ensure all URLs have the www.
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
第二次重写将帮助您实现您想要做的事情。
# This redirect all requests for http://example.com -> http://example.com/newdir
# If you are looking to redirect the request, so the URL contains directory name,
# you can change the [L] to [R=301,L]
RewriteRule ^$ /newdir [L]
# If your concerned about direct access to a particular page without the sub-dir
# you will want to add something like this
RewriteCond %{REQUEST_URI} !^/newdir
RewriteRule (.*) /newdir$1 [R=301,L]
因此,在这种情况下,您不必关心应用程序运行的域。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)