【问题标题】:Clean urls not working in Drupal 7 [closed]干净的网址在 Drupal 7 中不起作用 [关闭]
【发布时间】:2011-10-07 06:34:07
【问题描述】:

我刚刚安装并开始使用 Drupal 7,并按照说明打开了 Clean Urls。我单击了“运行 Clean URL 测试”按钮,但没有返回任何结果。它加载一些东西,然后刷新页面。

谁能解释为什么会发生这种情况以及我能做什么?

【问题讨论】:

  • 在您的项目根目录中打开您的 .htaccess 文件。取消注释 RewriteBase /drupal 并将其更改为您的项目名称,例如 RewriteBase /myprojectname Comment RewriteBase /
  • # 如果您的站点在 example.com 的 VirtualDocumentRoot 中运行,# 取消注释以下行:RewriteBase / godady I did like -> 它可以工作

标签: drupal-7 clean-urls


【解决方案1】:

有时以某种方式打开已清理的 URL 页面会失败并且不会显示错误(从系统的角度来看,我猜没有错误)。尝试手动更改 URL:

www.mydomain.com/?q=admin/config/search/clean-urls

到:

www.mydomain.com/admin/config/search/clean-urls

并查看它是否显示复选框,如果显示,选择它并保存。

【讨论】:

  • 感谢您,它为我在干净的 Ubuntu 12.04 LTS 测试版上修复了它。我已经正确设置了所有内容,mod_rewrite,allowoverride,但 Drupal 测试仍然失败。我想这只是 Drupal 中的一个错误,因为当您使用该 url 并启用它时,一切正常。
  • 哇。我希望我在浪费 3 个多小时之前阅读此内容。谢谢你!
  • 遇到了这个确切的问题。
  • 这也解决了我的问题。
  • 哇...谢谢。那行得通。
【解决方案2】:

创建文件phpinfo.php,内容:<?php phpinfo();?> 然后通过浏览器加载。查找文本“加载模块”,它应该包含“mod_rewrite”。如果没有,请在您的 apache 配置中启用它(您可能会问如何启用)。

【讨论】:

  • 已经启用。有没有办法以另一种方式设置干净的网址?这个按钮显然不适合我。
  • 哦,顺便说一句,我的 drupal 安装在服务器的子文件夹中,所以不是 root。我知道这是 Drupal 6 中的一个问题,但我不知道它在 Drupal 7 中是否仍然重要。
  • 好的,通过修改httpd.conf文件解决了。这个页面对我很有帮助:drupal.org/getting-started/clean-urls
  • 我阅读了该页面,发现我的问题是在我的 Apache 虚拟主机配置中需要“AllowOverride All”,这允许库存 Drupal .htaccess 工作,从而允许启用干净的 URL。
【解决方案3】:

您的 apache 配置文件 (/etc/apache2/apache2.conf) 必须包含以下 2 行。如果没有,则添加它们。这告诉 apache 在文件夹 “/var/www/drupal” 中查找 .htaccess 文件以进行设置

<Directory /var/www/drupal>
  AllowOverride All
</Directory>
AccessFileName .htaccess

【讨论】:

    【解决方案4】:

    我的 drupal7 安装在我的 Ubuntu 12.04 电脑上,位于文件夹 usr/share/drupal7 中。 我解决问题的方法是对我的 drupal7 文件夹中的 .htaccess 进行以下更改:

    #RewriteRule ^ index.php [L]
     RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 
    

    并添加:

    RewriteBase /drupal7
    

    不要添加RewriteBase /drupal

    现在测试正常,一切正常。

    【讨论】:

    • 我的 .htaccess 非常相似: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [ L,QSA]
    【解决方案5】:

    您必须在 apache 中启用 mod_rewrite 才能使干净的 url 工作

    如果 mod_rewrite 不在 phpinfo 中,您必须通过

    安装它
    sudo a2enmod rewrite
    
    sudo apache2ctl -l
    
    You need to replace the occurrence of AllowOverride none to AllowOverride all
    

    像这样改变

    <VirtualHost *:80>
    ServerAdmin admin@localhost
    
    DocumentRoot /var/www/
    <Directory />
    Options FollowSymLinks
    AllowOverride all
    </Directory>
    <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all
    </Directory>
    

    然后重启 apache

    sudo service apache2 restart
    

    【讨论】:

      【解决方案6】:

      我在 GoDaddy 上全新安装 Drupal 7.15 后遇到了问题。我必须对 .htaccess 进行以下更改才能使它们正常工作...

      # Pass all requests not referring directly to files in the filesystem to
      # index.php. Clean URLs are handled in drupal_environment_initialize().
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      #RewriteRule ^ index.php [L]
      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] #GoDaddy Hosting
      

      之后,Clean Url Test 仍然失败,但 Clean Url 实际上按照 artonice 的答案中所引用的那样工作。

      【讨论】:

        【解决方案7】:

        我在 GoDaddy 托管时也遇到过这个问题,但解决方案实际上很简单。

        取消注释 .htaccess 中的以下行后,干净的 URL 测试按预期通过:

        # RewriteBase /
        

        请注意,我的网站在域根目录下运行。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-06-29
          • 2018-04-22
          • 1970-01-01
          • 2013-06-06
          • 1970-01-01
          • 1970-01-01
          • 2012-09-27
          相关资源
          最近更新 更多