双重定向 mod_rewrite

发布于 2024-12-11 19:29:49 字数 957 浏览 0 评论 0原文

我试图在我的网页上配置一个 .htaccess 文件以使其按我想要的方式工作,但是经过大量搜索并尝试理解文档后,我的头对这些 mod_rewrite 感到困惑。

它看起来像这样:

root/index.php

root/application/-subfolders-

root/config/-files-

root/library/-files-

我想要的是将所有内容作为参数发送到index.php文件,如index.php ?page=$i,这样我就可以拥有像 www.mypage.com/foo/bar 这样的链接,我的 index.php 会处理它。 另外我希望将 www.mypage.com/js/文件名 发送到应用程序中的子文件夹, 例如 root/application/javascripts/文件名

我只是无法让它工作,尝试了我在这里和其他地方找到的不同答案。

.htaccess 现在是:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/js/ application/javascripts/ [L]
RewriteRule ^/js/(.*)$ application/javascripts/$1 [L]

RewriteRule ^css/ application/css/ [L]
RewriteRule ^css/(.*)$ application/css/$1 [L]

RewriteRule ^images/ application/images/ [L]
RewriteRule ^images/(.*)$ application/images/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php?page=$1 [NC]
</IfModule>

I am trying to configure a .htaccess file to my webpage to make it work as i want, but after a lot of searching and trying to understand the documentation, my head is just confused about these mod_rewrite.

It looks like this:

root/index.php

root/application/-subfolders-

root/config/-files-

root/library/-files-

what i want is everything sent to the index.php file as a parameter like index.php?page=$i, so i can have links like www.mypage.com/foo/bar and my index.php handles it.
ALSO i want to have the www.mypage.com/js/filename be sent to a subfolder in application,
like root/application/javascripts/filename.

I just cant get this to work, tried different answer i found both here and other places.

.htaccess at is now:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/js/ application/javascripts/ [L]
RewriteRule ^/js/(.*)$ application/javascripts/$1 [L]

RewriteRule ^css/ application/css/ [L]
RewriteRule ^css/(.*)$ application/css/$1 [L]

RewriteRule ^images/ application/images/ [L]
RewriteRule ^images/(.*)$ application/images/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php?page=$1 [NC]
</IfModule>

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

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

发布评论

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

评论(1

不醒的梦 2024-12-18 19:29:49

这应该可以做到:

RewriteEngine on

RewriteRule ^js/(.*)$ application/javascripts/$1 [L]

RewriteRule ^css/(.*)$ application/css/$1 [L]

RewriteRule ^images/(.*)$ application/images/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [NC]

This should do it:

RewriteEngine on

RewriteRule ^js/(.*)$ application/javascripts/$1 [L]

RewriteRule ^css/(.*)$ application/css/$1 [L]

RewriteRule ^images/(.*)$ application/images/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文