如何检查服务器上是否启用了mod_rewrite?
目前我正在使用 lightspeed 服务器托管。托管说 mod_rewrite
已启用,但我无法让我的脚本在那里工作。每当我尝试访问该 URL 时,它都会返回 404 - 未找到 页面。
我将相同的代码放在另一台运行 Apache 的服务器上。那里正在工作。所以我猜,这是 .htaccess
和 mod_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
从命令行输入
如果重写模式已经启用,它会告诉你!
from the command line, type
if the rewrite mode is already enabled, it will tell you so!
要检查 mod_rewrite 模块是否已启用,请在 WAMP 服务器的根文件夹中创建一个新的 php 文件。输入以下内容
phpinfo();
从浏览器访问您创建的文件。
CtrlF 打开搜索。搜索“mod_rewrite”。如果启用,您会将其视为“已加载模块”
如果未启用,请打开 httpd.conf(Apache 配置文件)并查找以下行。
#LoadModule rewrite_module module/mod_rewrite.so
删除开头的井号(“#”)并保存此文件。
重新启动您的 apache 服务器。
在浏览器中访问相同的 php 文件。
再次搜索“mod_rewrite”。您现在应该能够找到它。
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();
Access your created file from your browser.
CtrlF to open a search. Search for 'mod_rewrite'. If it is enabled you see it as 'Loaded Modules'
If not, open httpd.conf (Apache Config file) and look for the following line.
#LoadModule rewrite_module modules/mod_rewrite.so
Remove the pound ('#') sign at the start and save the this file.
Restart your apache server.
Access the same php file in your browser.
Search for 'mod_rewrite' again. You should be able to find it now.
如果您使用的是虚拟主机配置文件,请确保相关虚拟主机具有如下所示的指令
AllowOverride All
:基本上,这表示允许处理所有 .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:Basically, this states to allow processing of all .htaccess directives.
这适用于 CentOS:
应该输出
rewrite_module (shared)
This works on CentOS:
Should output
rewrite_module (shared)
如果 apache_get_modules() 无法识别或者 phpinfo() 中没有有关该模块的信息;尝试通过在 .htaccess 文件中添加这些行来测试 mod 重写:
和 mod_rewrite.php:
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:
And mod_rewrite.php:
安慰:
console:
如果
返回
true
则启用 mod-rewrite。If
returns
true
then mod-rewrite is enabled.PHP 的预定义
apache_get_modules()
函数返回已启用模块的列表。要检查mod_rewrite
是否已启用,您可以在服务器上运行以下脚本:如果上面的示例失败,您可以使用
.htaccess
文件验证 mod-rewrite。在文档根目录中创建一个
htaccess
文件并添加以下 rewriteRule :现在访问 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 ifmod_rewrite
is enabled , you can run the following script on your server :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 :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.
您可以在终端上执行此操作:
取自 2daygeek
you can do it on terminal, either:
taken from 2daygeek
如果此代码位于您的 .htaccess 文件中(没有检查 mod_rewrite.c),
并且您可以访问站点上的任何页面并收到 500 服务器错误,我认为可以肯定地说 mod 重写已打开。
If this code is in your .htaccess file (without the check for mod_rewrite.c)
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.
首先检查模块是否已安装如果
它没有显示在列表中,则必须激活它:
现在,重新启动服务器并测试
First you check if the module is installed
It it does not shows on the list, you must activate it:
Now, restart your server and test
您可以使用 php 函数
并检查 mod_rewrite
https://www.php.net/apache_get_modules
You can use php function
and check for mod_rewrite
https://www.php.net/apache_get_modules
如果您在Linux系统中,您可以在以下文件夹中检查apache2的所有启用模块(在我的例子中):/etc/apache2/mods-available
输入:
ll -a
< br>如果您想检查 php 的可用模块(在本例中为 php 7 )
文件夹 /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
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
to type:
ll -a
我知道这个问题已经很老了,但是如果您可以将 Apache 配置文件从
AllowOverride None
编辑为AllowOverride All
I know this question is old but if you can edit your Apache configuration file to
AllowOverride All
fromAllowOverride None
只需创建一个新页面并添加此代码
并运行此页面,然后 find 将能够知道模块是否可用,如果不可用,那么您可以询问您的主机,或者如果您想在本地计算机中启用它,则逐步检查此 youtube与在 wamp apache 中启用重写模块相关的教程
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp 服务器图标 ->阿帕奇-> Apache Modules 并检查重写模块选项
just make a new page and add this code
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
这段代码对我有用:
This code worked for me:
您只需输入
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
#
只需在根目录中创建一个 php 文件并添加以下代码
Simply create a php file in root and add following code
我遇到了确切的问题,我通过单击自定义结构解决了它,然后添加
/index.php/%postname%/
并且它有效希望这可以减轻我在寻找到底是什么时所经历的压力错了。
I was having the exact problem, I solved it by clicking custom structure, then adding
/index.php/%postname%/
and it worksHope this saves someone the stress that I went through finding what the heck was wrong with it.