通过index.php重写要路由的URL

发布于 2025-01-06 18:22:30 字数 176 浏览 1 评论 0原文

http://www.example.com/page 等 URL 重写为 http://www.example.com/?pg=page 的最佳方法是什么?当我这样做时,它可以工作,但是页面中的所有引用(例如 JavaScript 和 CSS)都会被伪造。请帮忙。

What would be the best way to rewrite URLs like http://www.example.com/page to http://www.example.com/?pg=page? When I do it, it works but all the references within the page like JavaScript and CSS get fudged. Please help.

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

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

发布评论

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

评论(2

云淡风轻 2025-01-13 18:22:30

当使用 mod 重写的 URL 时, href 变得非常有用!例如,

<html>
 <head>
  <base href="//www.example.com/" />
  <script type="text/javascript" src="js/script.js"></script>
  ...

无论 URL 是什么,该源都会正确地提供来自 www.example.com/js/script.js 的 js。

When using mod rewritten URLs, <base> hrefs become very useful! e.g.

<html>
 <head>
  <base href="//www.example.com/" />
  <script type="text/javascript" src="js/script.js"></script>
  ...

That source will properly serve the js from www.example.com/js/script.js not matter what the URL is.

漫雪独思 2025-01-13 18:22:30

你可以试试这个:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ ?pg=$1 [L,QSA]

You can try this:

RewriteEngine on
RewriteBase /

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