简体   繁体   English

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

[英].htaccess file to implement httpd.conf changes

I need to make the following changes to my server's httpd.conf 我需要对服务器的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. 但是,有人告诉我无法进行直接更改,因为它是Shell服务器,因此需要通过.htaccess文件使用mod_rewrite。

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 问候,肖恩

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. 我了解您的服务器设置为不允许您访问httpd.conf,而是使您能够创建.htaccess文件来执行所需的mod_rewrites。 This is a typical scenario. 这是一个典型的场景。 You do not need to write anything to httpd.conf to make that happen. 您无需为httpd.conf编写任何内容即可实现这一目标。 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. 要创建mod_rewrites,您需要使用任何名称不带扩展名的文本编辑器来创建.htaccess文件,该文件的扩展名不得带扩展名,而是使用前一个句点(。),然后直接将其保存到您的域根目录中。 www.yourdomain.com/.htaccess www.yourdomain.com/.htaccess

Inside this file you would then write your mod_rewrite code following this pattern: 在此文件内,您将按照以下模式编写mod_rewrite代码:

RewriteCond test_string cond_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: 以下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

A good article to read on this topic can be found at: fubra.com 可以在以下位置找到有关此主题的不错的文章: fubra.com

You cannot. 你不能。 Your settings basically instruct Apache to use .htaccess as per-directory configuration file and grant such files all available permissions. 您的设置基本上会指示Apache使用.htaccess作为每个目录的配置文件,并为这些文件授予所有可用的权限。 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. 有趣的是,鉴于.htaccess已经是默认值,而其他指令又是托管服务根据其策略授予或拒绝的内容,为什么您确实需要这些更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM