使用.htaccess重写php的路径包括

编程入门 行业动态 更新时间:2024-10-24 22:22:26
本文介绍了使用.htaccess重写php的路径包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不是.htaccess的专家,因此,如果这个问题听起来很愚蠢,那就对不起。

I am not expert for .htaccess, therefore sorry if this question sounds stupid.

我的ISP将整个网站都移到了新服务器上。根目录路径已更改。许多文件使用php包括将哪个路径硬编码为旧路径。我想避免手动重写所有内容。我正在尝试使用.htaccess,像这样:

My ISP moved the whole website to new server. Path to root changed. Many files use php include which path is hardcoded to old path. I would like to avoid rewriting everything manually. I am trying to use .htaccess, like this:

Options +FollowSymlinks RewriteEngine on RewriteRule /oldpath/(.*) /newpath/$1 [NC]

但是它不起作用。我该怎么办?

But it doesn't work. What do I do wrong?

推荐答案

mod_rewrite 由网络请求激活通过Apache而PHP include()可以直接访问文件系统,而绕过Web请求。因此,.htaccess文件中的任何 RewriteRules 都不会通过调用PHP include()或 require()函数。

mod_rewrite is activated by web requests through Apache whereas PHP include()s are direct access to the file system, which bypasses the web request. Therefore any RewriteRules in your .htaccess file will not be executed by calling PHPs include() or require() function.

在.htaccess文件中解决此问题的方法是像这样设置PHP包含路径:

The way to work round this in your .htaccess file is to set the PHP include path like so:

php_value include_path ".:/usr/local/lib/php:/your/new/base/include/path"

有关更改配置设置的详细信息,请参见PHP手册。

See the PHP manual for more information on changing configuration settings.

这也可以在带有以下内容的引导PHP文件中更改:

This can also be changed in a bootstrap PHP file with:

ini_set('include_path', ini_get('include_path') . ':/your/new/base/include/path');

绝对路径

您别无选择但要在整个代码库中进行查找和替换。正如@Crontab所建议的那样,您应该使用基本路径的中央声明。

Absolute Paths

You have little choice but to do a find and replace across the code base. As @Crontab suggested you should then use a central declaration of the base path.

更多推荐

使用.htaccess重写php的路径包括

本文发布于:2023-11-01 23:05:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   路径   htaccess   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!