.htaccess内容目录重写

发布于 2024-12-29 09:29:36 字数 379 浏览 1 评论 0原文

我在“内容”目录中有 php 文件,如下所示:

/wwwroot/content/about_us.php

还可能有子目录:

/wwwroot/content/team/team_bios.php

,我想在用户点击如下网址时向用户显示这些文件:

www.mydomain.com/about_us.php (/wwwroot/content/about_us.php) www.mydomain.com/team/team_bios.php (/wwwroot/content/team/team_bios.php)

I have php files in a 'content' directory like this:

/wwwroot/content/about_us.php

There could also be sub directories:

/wwwroot/content/team/team_bios.php

Using .htaccess, I want to show the user these files when they hit urls like this:

www.mydomain.com/about_us.php (/wwwroot/content/about_us.php)
www.mydomain.com/team/team_bios.php (/wwwroot/content/team/team_bios.php)

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

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

发布评论

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

评论(3

够钟 2025-01-05 09:29:36

将以下内容添加到站点 wwwroot 目录中的 .htaccess 文件中。

RewriteEngine on
RewriteBase /

#if this file exists in the content directory
RewriteCond %{DOCUMENT_ROOT}content%{REQUEST_URI} -f [NC] 
#then display it
RewriteRule ^ /content%{REQUEST_URI} [L]

Add the following to the .htaccess file in the wwwroot directory of your site.

RewriteEngine on
RewriteBase /

#if this file exists in the content directory
RewriteCond %{DOCUMENT_ROOT}content%{REQUEST_URI} -f [NC] 
#then display it
RewriteRule ^ /content%{REQUEST_URI} [L]
荒人说梦 2025-01-05 09:29:36

制定域的路由/wwwroot/content/。这样就会达到你想要的效果

Make the route of the domain /wwwroot/content/. This will have the effect you desire

一刻暧昧 2025-01-05 09:29:36

使用.htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /

  # do not rewrite if the request points to an actual file or directory on disk
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f

  # further, do not rewrite if the request starts with '/content/'
  RewriteCond %{REQUEST_URI} !^/content/

  # above conditions do not match; rewrite the URI to use '/content/' as prefix
  RewriteRule ^(.*)$ /content/$1 [L]
</IfModule>

Using .htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /

  # do not rewrite if the request points to an actual file or directory on disk
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f

  # further, do not rewrite if the request starts with '/content/'
  RewriteCond %{REQUEST_URI} !^/content/

  # above conditions do not match; rewrite the URI to use '/content/' as prefix
  RewriteRule ^(.*)$ /content/$1 [L]
</IfModule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文