.htaccess在实时站点上不起作用,但在本地主机上起作用?

.htaccess在实时站点上不起作用,但在本地主机上起作用?

问题描述:

我正在使用ExpressionEngine,并想从我的URL中删除index.php.我将这个.htaccess文件保存在根文件夹中.它可以在localhost上完美运行,但是当我将其上传到服务器时它不起作用.正确的URL显示在地址栏中,但页面停留在主页上.有提示吗?

I am using ExpressionEngine and want to remove index.php from my URL's. I have this .htaccess file saved in the root folder. It works perfectly on localhost but when I upload it to the server it doesn't work. The correct URL appears in the address bar but the page stays on homepage. Any tips?

<IfModule mod_rewrite.c>
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine On
    RewriteBase /
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
    RewriteCond %{THE_REQUEST} ^GET
    RewriteRule ^index\.php(.+) $1 [R=301,L]
    # Standard ExpressionEngine Rewrite
    # ------------------------------
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

确保您的

Make sure your AllowOverride Directive in Apache is configured to allow .htaccess files and your server has mod_rewrite installed and active.

在Mac OS X上,您可以在/etc/apache2/httpd.conf上找到此文件.查找<Directory>指令并将其更改为:

On Mac OS X, you'll find this file at /etc/apache2/httpd.conf. Look for the <Directory> Directive and change it to be:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
</Directory>

您需要重新启动Apache,以便它可以读取新配置:

You'll need to restart Apache so it can read the new configuration:

sudo /usr/sbin/apachectl restart

如果您希望使用GUI重新启动Apache,请转到 Apple>系统偏好设置>共享,然后切换 Web共享服务旁边的复选框.

If you'd prefer to use a GUI to restart Apache, go to Apple > System Preferences > Sharing and toggle the checkbox next to the Web Sharing service.

如果您使用Windows或任何版本的Linux,则采用相同的方法,但是Apache配置可能位于不同的位置,尤其是在使用 MAMP .

If you're using Windows or any flavor of Linux, the same approach applies, but the Apache configuration may be in a different place, especially if you're using WAMP or MAMP.

此外,EllisLab为删除index.php的官方支持的方法"供参考.来自ExpressionEngine URLs :

Also, for reference, the "officially supported method" by EllisLab for Removing index.php from ExpressionEngine URLs is the following:

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Removes index.php
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    # If 404s, "No Input File" or every URL returns the same thing
    # make it /index.php?/$1 above (add the question mark)
</IfModule>