如何检查是否在服务器上启用mod_rewrite?
目前我正在使用光速服务器托pipe。 主机说mod_rewrite已启用,但我不能让我的脚本在那里工作。 每当我尝试访问的URL,它返回404  – 找不到页面。 
 我把相同的代码放在另一台运行Apache的服务器上。 在那边工作 所以我想,这是.htaccess和mod_rewrite问题。 
但Hosting的支持仍然坚持,他们的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] 
但是同样的结果。
- 
要检查mod_rewrite模块是否启用,请在您的WAMP服务器的根文件夹中创build一个新的php文件。 input以下内容 phpinfo();
- 
从您的浏览器访问您创build的文件。 
- 
按Ctrl F打开search。 search“mod_rewrite”。 如果启用,则将其视为“已加载模块” 
- 
如果没有,打开httpd.conf(Apacheconfiguration文件)并查找以下行。 #LoadModule rewrite_module modules/mod_rewrite.so
- 
在开始时删除井号('#')并保存该文件。 
- 
重新启动你的Apache服务器。 
- 
在浏览器中访问相同的php文件。 
- 
再次search“mod_rewrite”。 你现在应该可以find它。 
 如果您正在使用虚拟主机configuration文件,请确保所涉及的虚拟主机具有指令AllowOverride All ,如下所示: 
 <VirtualHost *:80> ... <Directory ...> AllowOverride All </Directory> </VirtualHost> 
从命令行input
sudo a2enmod重写
如果重写模式已经启用,它会告诉你的!
如果apache_get_modules()在phpinfo()中没有被识别或者没有关于这个模块的信息; 尝试通过在.htaccess文件中添加这些行来testingmod重写:
 RewriteEngine On RewriteRule ^.*$ mod_rewrite.php 
和mod_rewrite.php:
 <?php echo "Mod_rewrite is activated!"; ?> 
安慰:
 <VirtualHost *:80> ... <Directory ...> AllowOverride All </Directory> </VirtualHost> sudo a2enmod rewrite sudo service apache2 restart 
如果
 in_array('mod_rewrite', apache_get_modules()) 
 返回true然后mod-rewrite被启用。 
如果这个代码在你的.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重写打开。
你可以使用php函数
  apache_get_modules 
并检查mod_rewrite
 <pre> <?php print_r(apache_get_modules()); ?> </pre> 
如果你在linux系统下,你可以在下面的文件夹中检查apache2的所有启用模块(在我的情况下):/ etc / apache2 / mods-available
 cd /etc/apache2/mods-available 
 键入: ll -a 
 如果你想检查可用的模块为PHP(在这种情况下,PHP 7)文件夹/etc/php/7.0/mods-available 
 cd /etc/php/7.0/mods-available 
 键入: ll -a 
  PHP的perdefined apache_get_modules()函数返回已启用模块的列表。 要检查是否启用了mod_rewrite ,可以在服务器上运行以下脚本: 
 <?php print_r(apache_get_modules()); ?> 
 如果上面的例子失败了,你可以使用你的.htaccess文件validationmod-rewrite。 
 在文档根目录下创build一个htaccess文件并添加下面的rewriteRule: 
 RewriteEngine on RewriteRule ^helloWorld/?$ /index.php [NC,L] 
现在访问http://example.com/HelloWorld ,您将在内部转发到您网站的/index.php页面。 否则,如果mod-rewrite被禁用,将会得到500个Internel服务器错误。
希望这可以帮助。
只是做一个新的页面,并添加此代码
  <?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将能够知道模块是否可用,如果不是那么你可以问你的主机,或者如果你想在本地机启用它,然后检查这一步的教程有关启用重写模块在Apache Apache https://youtu.be/xIspOX9FuVU?t=1m43s Wamp服务器图标 – > Apache – > Apache模块并检查重写模块选项
这适用于CentOS:
 $ sudo httpd -M |grep rewrite_module 
 应该输出rewrite_module (shared)