.htaccess 无法在实时站点上工作,但在本地主机上工作?

发布于 2024-11-26 18:19:44 字数 792 浏览 7 评论 0原文

我正在使用 ExpressionEngine,并且想要从我的 URL 中删除 index.php。我将此 .htaccess 文件保存在根文件夹中。它在本地主机上完美运行,但是当我将其上传到服务器时它不起作用。正确的 URL 显示在地址栏中,但页面仍保留在主页上。有什么建议吗?

<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>

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>

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

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

发布评论

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

评论(1

你爱我像她 2024-12-03 18:19:44

确保您的 Apache 中的AllowOverride指令配置为允许.htaccess 文件,并且您的服务器已安装并激活 mod_rewrite

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

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

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

sudo /usr/sbin/apachectl restart

如果您希望使用 GUI 来重新启动 Apache,请转到到苹果>系统偏好设置>共享并切换网络共享服务旁边的复选框。

如果您使用的是 Windows 或任何版本的 Linux,则适用相同的方法,但 Apache 配置可能位于不同的位置,特别是如果您使用的是 WAMPMAMP


另外,作为参考,EllisLab 的“官方支持的方法” 从 ExpressionEngine URL 中删除 index.php 如下:

<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>

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

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>

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

sudo /usr/sbin/apachectl restart

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.

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.


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