.htaccess 文件来实现 httpd.conf 更改

发布于 2025-01-01 15:19:55 字数 345 浏览 1 评论 0原文

我需要对服务器的 httpd.conf 进行以下更改

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

AllowOverride All
AccessFileName .htaccess

但是,我被告知无法直接更改,因为它是 shell 服务器,因此需要通过 .htaccess 文件使用 mod_rewrite。

我现在的问题是,如何转换代码?我尝试到处搜索但找不到任何答案。抱歉,我是这个领域的新手。

非常感谢。

问候, 肖恩

I need to make the following changes to my server's httpd.conf

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

AllowOverride All
AccessFileName .htaccess

However, i was told that making direct change is not possible as it is a shell server so there is a need to use mod_rewrite via a .htaccess file.

My question is now, how do I convert the codes? I've tried searching everywhere but could not find any answer to this. Sorry that I am a newbie in this area.

Thank you very much.

Regards,
Sean

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

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

发布评论

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

评论(2

离鸿 2025-01-08 15:19:55

你不能。您的设置基本上指示 Apache 使用 .htaccess 作为每个目录的配置文件,并授予此类文件所有可用权限。显然:

  1. 您不能在该文件中添加查找文件的指令(就像将保险箱的钥匙放在上锁的保险箱内一样)。
  2. 不允许该文件向自己授予这些权限。

有趣的一点是,考虑到 .htaccess 已经是默认值,而其他指令是托管服务根据其策略授予或拒绝的,那么为什么您确实需要这些更改。

You cannot. Your settings basically instruct Apache to use .htaccess as per-directory configuration file and grant such files all available permissions. Obviously:

  1. You can't put instructions to find a file in that file (it's like keeping the safe's keys inside the locked safe).
  2. The file is not allowed to grant himself those permissions.

The interesting point is why exactly you need those changes, given that .htaccess is already the default value and the other directives are something the hosting services grant or deny according to their policies.

慕巷 2025-01-08 15:19:55

据我了解,您的服务器设置为不允许您访问 httpd.conf,而是让您能够创建 .htaccess 文件来执行所需的 mod_rewrites。这是一个典型的场景。您无需向 httpd.conf 写入任何内容即可实现这一点。它已经为你做好了。

要创建 mod_rewrites,您需要使用任何文本编辑器创建一个 .htaccess 文件,该文件具有该名称且无扩展名,但前面带有句点 (.),并将其直接保存到您的域根目录,例如。 www.yourdomain.com/.htaccess

在此文件中,您将按照以下模式编写 mod_rewrite 代码:

RewriteCond  测试字符串cond_pattern

以下 mod_rewrite 代码通常与 WordPress 一起使用,以允许页面和帖子具有更合理的永久链接模式:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

有关此主题的好文章可以在以下位置找到:fubra.com

I understand that your server is set to not allow you access to httpd.conf but rather gives you the ability to create .htaccess files to do your needed mod_rewrites. This is a typical scenario. You do not need to write anything to httpd.conf to make that happen. It is already done for you.

To create mod_rewrites you need to create an .htaccess file with any text editor with that name and no extension but with a preceding period (.) and save it to your domain root directly eg. www.yourdomain.com/.htaccess

Inside this file you would then write your mod_rewrite code following this pattern:

RewriteCond   test_string   cond_pattern

The following mod_rewrite code is oftentimes used with WordPress to allow pages and posts to have a more sensible permalink pattern:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

A good article to read on this topic can be found at: fubra.com

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