.htaccess 重定向到目录

发布于 2024-08-11 18:39:40 字数 792 浏览 1 评论 0原文

这是一个非常愚蠢的问题,但我在 htaccess 方面很弱。

我想要位于 http://localhost/template/* 的所有文件(php、css、javascript 和图像)指向 http://localhost/* 以及位于 http://localhost/tempalte/404.php

我几乎在这里得到它,但当我更改时,

RewriteRule ^(.*)\.(css|php|js|png|gif) template/$1 [NC,L] to
RewriteRule ^(.*)\.(css|php|js|png|gif) template/$1.$2 [NC,L] 

我收到内部服务器错误。

# BEGIN website
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.(css|php|js|png|gif) template/$1 [NC,L] 
</IfModule>

Options -Indexes
# END website

This is a very silly question but I am pretty weak in htaccess.

I want all files (php, css, javascripts and images) located at http://localhost/template/* to point to http://localhost/* along with a 404 Error Handler that is located at http://localhost/tempalte/404.php

I almost got it here but when I change

RewriteRule ^(.*)\.(css|php|js|png|gif) template/$1 [NC,L] to
RewriteRule ^(.*)\.(css|php|js|png|gif) template/$1.$2 [NC,L] 

I get an internal server error.

# BEGIN website
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.(css|php|js|png|gif) template/$1 [NC,L] 
</IfModule>

Options -Indexes
# END website

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤云独去闲 2024-08-18 18:39:40

编辑以反映评论,试试这个:

# BEGIN website
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*\.(css|php|js|png|gif)) template/$1 [NC,L] 
</IfModule>

Options -Indexes
# END website

Edited to reflect comments, try this:

# BEGIN website
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*\.(css|php|js|png|gif)) template/$1 [NC,L] 
</IfModule>

Options -Indexes
# END website
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文