.htaccess,当没有 url 段时重定向到子文件夹
.htaccess, redirect to subfolder when no url segment
我开发了一个CI网站,并托管在服务器根目录,我还创建了一些静态html页面并将它们放在website
目录中。 (见下文)
public_html
/application
/other ci folder
/index.php
/.htaccess
/website // in this directory i have my static html website
所以当我输入 www.myweb.com
时,我可以访问我的 CI 应用程序,
CI 应用程序有 2 条主要路线。
www.myweb.com for front end
www.myweb.com/admin backend
现在我可以使用访问静态 html 站点
www.myweb.com/website
我想要的是:
当我输入
www.myweb.com
它应该显示静态 html 网站
www.myweb.com/app
它应该显示 ci 网站的前端
www.myweb.com/admin
它现在应该可以正常工作了
我试过的是:
我搜索了 google/stack 溢出并找到了一些 .htaccess 解决方案,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?myweb\.com$ [NC]
RewriteRule !^website/ /website%{REQUEST_URI} [L,NC]
#above line works good and show website from website folder
RewriteCond %{HTTP_HOST} ^(www\.)?myweb\.com$ [NC]
RewriteRule (.*)/ %{REQUEST_URI} [L,NC]
#when i add these two line website shows 500 internal server error
#Other CI htaccess code to remove index.php
</IfModule>
你能给我建议解决方案吗?谢谢
我找到了我的问题的解决方案,我想分享它
<IfModule mod_rewrite.c>
RewriteEngine On
# If the requested URI is empty...
RewriteCond %{REQUEST_URI} !^$
# ...then redirect to the "website" folder
^/?$ /website/ [L] //or[L,R] if you want to redirect
# Otherwise rewrite the base
RewriteBase /
# If the request is not a folder or a file, redirects to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我将我的资产与 codeigniter 资产合并(更正了 css 和 js 的一些路径)所以它对我有用。
希望它对某人有用。
得到了这个 post 的帮助:.htaccess - When there is no requested URI
我开发了一个CI网站,并托管在服务器根目录,我还创建了一些静态html页面并将它们放在website
目录中。 (见下文)
public_html
/application
/other ci folder
/index.php
/.htaccess
/website // in this directory i have my static html website
所以当我输入 www.myweb.com
时,我可以访问我的 CI 应用程序,
CI 应用程序有 2 条主要路线。
www.myweb.com for front end
www.myweb.com/admin backend
现在我可以使用访问静态 html 站点
www.myweb.com/website
我想要的是:
当我输入
www.myweb.com
它应该显示静态 html 网站
www.myweb.com/app
它应该显示 ci 网站的前端
www.myweb.com/admin
它现在应该可以正常工作了
我试过的是:
我搜索了 google/stack 溢出并找到了一些 .htaccess 解决方案,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?myweb\.com$ [NC]
RewriteRule !^website/ /website%{REQUEST_URI} [L,NC]
#above line works good and show website from website folder
RewriteCond %{HTTP_HOST} ^(www\.)?myweb\.com$ [NC]
RewriteRule (.*)/ %{REQUEST_URI} [L,NC]
#when i add these two line website shows 500 internal server error
#Other CI htaccess code to remove index.php
</IfModule>
你能给我建议解决方案吗?谢谢
我找到了我的问题的解决方案,我想分享它
<IfModule mod_rewrite.c>
RewriteEngine On
# If the requested URI is empty...
RewriteCond %{REQUEST_URI} !^$
# ...then redirect to the "website" folder
^/?$ /website/ [L] //or[L,R] if you want to redirect
# Otherwise rewrite the base
RewriteBase /
# If the request is not a folder or a file, redirects to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我将我的资产与 codeigniter 资产合并(更正了 css 和 js 的一些路径)所以它对我有用。
希望它对某人有用。
得到了这个 post 的帮助:.htaccess - When there is no requested URI