【问题标题】:location of .htaccess file.htaccess 文件的位置
【发布时间】:2015-01-01 14:52:05
【问题描述】:

/var/www/html/My_project_folder 是我的项目的路径。我没有找到 .htaccess 文件。我想粘贴我编辑的 .htaccess 文件。但我不确定我需要放在哪个位置? 我的htaccess文件代码是--

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

 # Enable expirations
 ExpiresActive On

 # Default directive
 ExpiresDefault "access plus 1 month"

 # My favicon
 ExpiresByType image/x-icon "access plus 1 year”

 # Images
 ExpiresByType image/gif "access plus 1 month"
 ExpiresByType image/png "access plus 1 month"
 ExpiresByType image/jpg "access plus 1 month"
 ExpiresByType image/jpeg "access plus 1 month"

 # CSS
 ExpiresByType text/css "access 1 month”

 # Javascript
 ExpiresByType application/javascript "access plus 1 year"

 </IfModule>

 AddOutputFilterByType DEFLATE text/plain
 AddOutputFilterByType DEFLATE text/html
 AddOutputFilterByType DEFLATE text/xml
 AddOutputFilterByType DEFLATE text/css
 AddOutputFilterByType DEFLATE application/xml
 AddOutputFilterByType DEFLATE application/xhtml+xml
 AddOutputFilterByType DEFLATE application/rss+xml
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE application/x-javascript

我在 .htaccess 文件中添加了这段代码以加速我的网站。请帮助我找到 .htaccess 文件的位置。提前致谢!

【问题讨论】:

    标签: html .htaccess web pagespeed


    【解决方案1】:

    通常,此文件位于您网站的根目录(index.php 文件所在的位置)。如果没有,您可以创建一个新文件。但请注意不要使用记事本创建类似“.htaccess.txt”的内容(通常会将 .txt 附加到所有文件中)。

    【讨论】:

      【解决方案2】:

      您需要将 .htaccess 文件粘贴到项目的根目录中。 您的 .htaccess 可能被隐藏了...尝试使用终端而不是 DM 查看该文件夹,如果不存在,请尝试使用该命令从终端创建一个新文件。

      nano .htaccess(Linux 用户)
      编辑 .htaccess(Windows 用户)

      【讨论】:

      • 我的项目的根目录意味着我需要在项目文件夹下创建这个 .htaccess 文件?
      • 是的,完全在“/var/www/html/My_project_folder”中。并检查您是否使用“a2enmod rewrite”在 apache 上启用了 mod,否则您的 .htaccess 文件将无用
      • 谢谢。我可以知道如何通过 ssh 启用 mod 吗?
      • 如果我在 www 下粘贴 .htaccess 文件会不会给服务器带来麻烦。因为首先我是这样尝试的,但我得到“网络连接意外关闭”
      • 我认为您将虚拟主机配置为 www 目录作为根目录...所以 .htaccess 正在工作,但找不到正确的路径...用简单的方法进行测试.htaccess like this qualitytuts.com/check-htaccess-is-working-or-not-on-server 这里可以找到主机配置示例httpd.apache.org/docs/2.2/vhosts/examples.html
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多