如何检查服务器上是否启用了mod_rewrite?

发布于 2024-12-03 04:47:55 字数 1100 浏览 2 评论 0原文

目前我正在使用 lightspeed 服务器托管。托管说 mod_rewrite 已启用,但我无法让我的脚本在那里工作。每当我尝试访问该 URL 时,它都会返回 404 - 未找到 页面。

我将相同的代码放在另一台运行 Apache 的服务器上。那里正在工作。所以我猜,这是 .htaccessmod_rewrite 问题。

但托管支持仍然坚持要求我他们的 mod_rewrite 已打开,所以我想知道如何检查它是否实际上已启用。

我尝试检查 phpinfo(),但没有运气,我在那里找不到 mod_rewrite,是因为他们使用的是 lightspeed 吗?

有什么办法可以检查吗?请帮帮我。谢谢。

仅供参考:我的.htaccess代码

Options -Indexes

<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>

我也尝试过,

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

但结果相同。

Currently I am using the hosting with lightspeed server. Hosting says mod_rewrite is enabled but I can't get my script working there. Whenever I try to access the URL, it returns 404 - not found page.

I put the same codes at another server which is running with Apache. It's working over there. So I guess, it's the .htaccess and mod_rewrite issue.

But Hosting support is still insisting with me that their mod_rewrite is on, so I would like to know how can I check whether it's actually enabled or not.

I tried to check with phpinfo(), but no luck, I can't find mod_rewrite there, is it because they are using lightspeed?

Is there any way to check? Please help me out. Thank you.

FYI: my .htaccess code is

Options -Indexes

<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>

I tried like this also

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

But same result.

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

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

发布评论

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

评论(19

漫漫岁月 2024-12-10 04:47:55

从命令行输入

sudo a2enmod 重写

如果重写模式已经启用,它会告诉你!

from the command line, type

sudo a2enmod rewrite

if the rewrite mode is already enabled, it will tell you so!

静谧幽蓝 2024-12-10 04:47:55
  1. 要检查 mod_rewrite 模块是否已启用,请在 WAMP 服务器的根文件夹中创建一个新的 php 文件。输入以下内容

    phpinfo();

  2. 从浏览器访问您创建的文件。

  3. CtrlF 打开搜索。搜索“mod_rewrite”。如果启用,您会将其视为“已加载模块”

  4. 如果未启用,请打开 httpd.conf(Apache 配置文件)并查找以下行。

    #LoadModule rewrite_module module/mod_rewrite.so

  5. 删除开头的井号(“#”)并保存此文件。

  6. 重新启动您的 apache 服务器。

  7. 在浏览器中访问相同的 php 文件。

  8. 再次搜索“mod_rewrite”。您现在应该能够找到它。

  1. To check if mod_rewrite module is enabled, create a new php file in your root folder of your WAMP server. Enter the following

    phpinfo();

  2. Access your created file from your browser.

  3. CtrlF to open a search. Search for 'mod_rewrite'. If it is enabled you see it as 'Loaded Modules'

  4. If not, open httpd.conf (Apache Config file) and look for the following line.

    #LoadModule rewrite_module modules/mod_rewrite.so

  5. Remove the pound ('#') sign at the start and save the this file.

  6. Restart your apache server.

  7. Access the same php file in your browser.

  8. Search for 'mod_rewrite' again. You should be able to find it now.

动听の歌 2024-12-10 04:47:55

如果您使用的是虚拟主机配置文件,请确保相关虚拟主机具有如下所示的指令 AllowOverride All

<VirtualHost *:80>
        ...
    <Directory "directory/of/your/.htaccess">
        AllowOverride All
    </Directory>
</VirtualHost>

基本上,这表示允许处理所有 .htaccess 指令。

If you are using a virtual hosts configuration file, make sure the virtual host in question has the directive AllowOverride All somewhere like this:

<VirtualHost *:80>
        ...
    <Directory "directory/of/your/.htaccess">
        AllowOverride All
    </Directory>
</VirtualHost>

Basically, this states to allow processing of all .htaccess directives.

内心激荡 2024-12-10 04:47:55

这适用于 CentOS:

$ sudo httpd -M |grep rewrite_module

应该输出 rewrite_module (shared)

This works on CentOS:

$ sudo httpd -M |grep rewrite_module

Should output rewrite_module (shared)

最舍不得你 2024-12-10 04:47:55

如果 apache_get_modules() 无法识别或者 phpinfo() 中没有有关该模块的信息;尝试通过在 .htaccess 文件中添加这些行来测试 mod 重写:

RewriteEngine On
RewriteRule ^.*$ mod_rewrite.php

和 mod_rewrite.php:

<?php echo "Mod_rewrite is activated!"; ?>

If apache_get_modules() is not recognized or no info about this module in phpinfo(); try to test mod rewrite by adding those lines in your .htaccess file:

RewriteEngine On
RewriteRule ^.*$ mod_rewrite.php

And mod_rewrite.php:

<?php echo "Mod_rewrite is activated!"; ?>
小猫一只 2024-12-10 04:47:55

安慰:

<VirtualHost *:80>
        ...
    <Directory ...>
        AllowOverride All
    </Directory>
</VirtualHost>

sudo a2enmod rewrite
sudo service apache2 restart

console:

<VirtualHost *:80>
        ...
    <Directory ...>
        AllowOverride All
    </Directory>
</VirtualHost>

sudo a2enmod rewrite
sudo service apache2 restart
清引 2024-12-10 04:47:55

如果

in_array('mod_rewrite', apache_get_modules())

返回 true 则启用 mod-rewrite。

If

in_array('mod_rewrite', apache_get_modules())

returns true then mod-rewrite is enabled.

风透绣罗衣 2024-12-10 04:47:55

PHP 的预定义 apache_get_modules() 函数返回已启用模块的列表。要检查 mod_rewrite 是否已启用,您可以在服务器上运行以下脚本:

<?php
print_r(apache_get_modules());
?>

如果上面的示例失败,您可以使用 .htaccess 文件验证 mod-rewrite。

在文档根目录中创建一个 htaccess 文件并添加以下 rewriteRule :

RewriteEngine on

RewriteRule ^helloWorld/?$ /index.php [NC,L]

现在访问 http://example。 com/HelloWorld ,您将被内部转发到您网站的 /index.php 页面。否则,如果 mod-rewrite 被禁用,您将收到 500 Internel 服务器错误。

希望这有帮助。

PHP's perdefined apache_get_modules() function returns a list of enabled modules. To check if mod_rewrite is enabled , you can run the following script on your server :

<?php
print_r(apache_get_modules());
?>

If the above example fails, you can verify mod-rewrite using your .htaccess file.

Create an htaccess file in the document root and add the following rewriteRule :

RewriteEngine on

RewriteRule ^helloWorld/?$ /index.php [NC,L]

Now visit http://example.com/HelloWorld , You will be internally forwarded to /index.php page of your site. Otherwise, if mod-rewrite is disabled , you will get a 500 Internel server error.

Hope this helps.

累赘 2024-12-10 04:47:55

您可以在终端上执行此操作:

apachectl -M
apache2ctl -M

取自 2daygeek

you can do it on terminal, either:

apachectl -M
apache2ctl -M

taken from 2daygeek

氛圍 2024-12-10 04:47:55

如果此代码位于您的 .htaccess 文件中(没有检查 mod_rewrite.c),

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

并且您可以访问站点上的任何页面并收到 500 服务器错误,我认为可以肯定地说 mod 重写已打开。

If this code is in your .htaccess file (without the check for mod_rewrite.c)

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

and you can visit any page on your site with getting a 500 server error I think it's safe to say mod rewrite is switched on.

日暮斜阳 2024-12-10 04:47:55

首先检查模块是否已安装如果

apachectl -M

它没有显示在列表中,则必须激活它:

a2enmod rewrite

现在,重新启动服务器并测试

systemctl restart apache2

First you check if the module is installed

apachectl -M

It it does not shows on the list, you must activate it:

a2enmod rewrite

Now, restart your server and test

systemctl restart apache2
○闲身 2024-12-10 04:47:55

您可以使用 php 函数

      apache_get_modules

并检查 mod_rewrite

<pre>
<?php
print_r(apache_get_modules());
?>
</pre>

https://www.php.net/apache_get_modules

You can use php function

      apache_get_modules

and check for mod_rewrite

<pre>
<?php
print_r(apache_get_modules());
?>
</pre>

https://www.php.net/apache_get_modules

慢慢从新开始 2024-12-10 04:47:55

如果您在Linux系统中,您可以在以下文件夹中检查apache2的所有启用模块(在我的例子中):/etc/apache2/mods-available

cd /etc/apache2/mods-available

输入:ll -a< br>
如果您想检查 php 的可用模块(在本例中为 php 7 )
文件夹 /etc/php/7.0/mods-available

cd /etc/php/7.0/mods-available

输入:ll -a

If you are in linux system, you can check all enable modules for apache2(in my case) in the following folder:/etc/apache2/mods-available

cd /etc/apache2/mods-available

to type: ll -a
if you want to check the available modules for php (in this case php 7 )
folder /etc/php/7.0/mods-available

cd /etc/php/7.0/mods-available

to type: ll -a

青丝拂面 2024-12-10 04:47:55

我知道这个问题已经很老了,但是如果您可以将 Apache 配置文件从 AllowOverride None 编辑为 AllowOverride All

<Directory "${SRVROOT}/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

I know this question is old but if you can edit your Apache configuration file to AllowOverride All from AllowOverride None

<Directory "${SRVROOT}/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>
不气馁 2024-12-10 04:47:55

只需创建一个新页面并添加此代码

 <?php
 if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
 $res = 'Module Unavailable';
 if(in_array('mod_rewrite',apache_get_modules())) 
 $res = 'Module Available';
?>
<html>
<head>
<title>A mod_rewrite availability check !</title></head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>

并运行此页面,然后 find 将能够知道模块是否可用,如果不可用,那么您可以询问您的主机,或者如果您想在本地计算机中启用它,则逐步检查此 youtube与在 wamp apache 中启用重写模块相关的教程
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp 服务器图标 ->阿帕奇-> Apache Modules 并检查重写模块选项

just make a new page and add this code

 <?php
 if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
 $res = 'Module Unavailable';
 if(in_array('mod_rewrite',apache_get_modules())) 
 $res = 'Module Available';
?>
<html>
<head>
<title>A mod_rewrite availability check !</title></head>
<body>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>
</body>
</html>

and run this page then find will able to know module is Available or not if not then you can ask to your hosting or if you want to enable it in local machine then check this youtube step by step tutorial related to enable rewrite module in wamp apache
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp server icon -> Apache -> Apache Modules and check the rewrite module option

楠木可依 2024-12-10 04:47:55

这段代码对我有用:

if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) echo "mod_rewrite enabled";
else echo "mod_rewrite disabled";

This code worked for me:

if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) echo "mod_rewrite enabled";
else echo "mod_rewrite disabled";
喵星人汪星人 2024-12-10 04:47:55

您只需输入

cat /etc/apache2/mods-available/rewrite.load

检查该文件是否存在即可。结果行可能不会以 # 开头进行注释

You just need to check whether the file is there, by typing

cat /etc/apache2/mods-available/rewrite.load

The result line may not be commented starting with #

深海蓝天 2024-12-10 04:47:55

只需在根目录中创建一个 php 文件并添加以下代码

<?php
if (in_array('mod_rewrite', apache_get_modules())) {
    echo "mod_rewrite is enabled";
} else {
    echo "mod_rewrite is not enabled";
}

Simply create a php file in root and add following code

<?php
if (in_array('mod_rewrite', apache_get_modules())) {
    echo "mod_rewrite is enabled";
} else {
    echo "mod_rewrite is not enabled";
}
天生の放荡 2024-12-10 04:47:55

我遇到了确切的问题,我通过单击自定义结构解决了它,然后添加 /index.php/%postname%/ 并且它有效

希望这可以减轻我在寻找到底是什么时所经历的压力错了。

I was having the exact problem, I solved it by clicking custom structure, then adding /index.php/%postname%/ and it works

Hope this saves someone the stress that I went through finding what the heck was wrong with it.

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