关于模块重写的语法

发布于 2024-09-15 09:50:37 字数 886 浏览 2 评论 0原文

我对模块重写的语法有一些疑问。我想知道如何编写不包含/包含某些文件的规则?

例如:

目录结构:

  • /
  • /home.php
  • /profile.php
  • /pages
  • /pages/index.php
  • /pages/.htaccess

关于 /pages/index.php 内容:

<?php include_once "../home.php" ?>

关于 /home。 php 内容:

<a href="profile.php">Profile</a>

所以:我想在页面目录中编写一个 .htaccess,并使超链接(profile.php)在用户单击个人资料文本时正确。

RewriteEngine On
RewriteBase /pages2

RewriteRule ^(images|css|js|plugins)/(.*) http://localhost/$1/$2

# if end with .php ext and file name not index.php then redirect to parent directory
RewriteCond %{SCRIPT_FILENAME} .php$
RewriteCond %{SCRIPT_FILENAME} !index.php$ ## not work ?
RewriteRule ^(.*) http://localhost/$1

在这种情况下,我无法更改根路径文件内容。

i have some question about the syntax of module rewrite. i would like to know how to write a rule to not include/contain some file?

For example:

Directories structure:

  • /
  • /home.php
  • /profile.php
  • /pages
  • /pages/index.php
  • /pages/.htaccess

About the /pages/index.php content:

<?php include_once "../home.php" ?>

About the /home.php content:

<a href="profile.php">Profile</a>

So: i would like to write a .htaccess in the pages directory, and make the hyperlink (profile.php) is correct when user click on Profile text.

RewriteEngine On
RewriteBase /pages2

RewriteRule ^(images|css|js|plugins)/(.*) http://localhost/$1/$2

# if end with .php ext and file name not index.php then redirect to parent directory
RewriteCond %{SCRIPT_FILENAME} .php$
RewriteCond %{SCRIPT_FILENAME} !index.php$ ## not work ?
RewriteRule ^(.*) http://localhost/$1

In this case , i can not change the root path file content.

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

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

发布评论

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

评论(1

亣腦蒛氧 2024-09-22 09:50:37

哈哈,你不需要任何规则:) 就去做吧

<a href="/profile.php">Profile</a>

lol you don't need any rules :) just make it

<a href="/profile.php">Profile</a>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文