How to check mod_rewrite in PHP CGI

I am on a shared host, and PHP is not considered a CGI script, and this is all a problem, I can’t find out if mod_rewrite will be allowed or not

Note: I don't have any root level access so i can't much do with Shell.

I tried the following:
1) registered in phpinfo () , where I found out that this is the wrong place to search in PHP-CGI.


2) I tried to get it from apache_get_modules, which agi does not work in PHP-CGI :(
3) I tried:

 if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) { // mod_rewrite is enabled } 

which asks for the path to apache, and I do not have this information. SHELL cannot answer me, and $ _SERVER has nothing.
4) I checked with RewriteEngine On in .htaccess and after that my site throws 500 Internal server error may be because RewriteEngine does not exist, but I need it to be written to show someone.

Any body has any idea how to check if this DONE is received.

thanks

+4
source share
2 answers

With PHP CGI, there is no easy way to find out if mod_rewrite is available or not on the server.

So, you need to find out by making a test call to the server. You can use the following steps for this method,

  • Create a directory on the server named mod_rewrite_test .

  • Add the .htaccess file to this directory with the following code,

    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /mod_rewrite_test RewriteRule .* mod_rewrite_test.txt </IfModule>

    a. the first line tells apache to execute the code below only if mod_rewrite is available,
    b. the second line allows you to rewrite the engine,
    from. the third line overwrites the base directory path, which is from DOCUMENT_ROOT
    e. the fourth line returns the contents of the mod_rewrite_test.txt file to any request sent to the mod_rewrite_test directory.

  • Create a file called mod_rewrite_test.txt in the same directory. Write ok in this file and save it.

  • Now, using CURL in your PHP script, call a URL similar to

    http://www.your-domain.com/mod_rewrite_test/test.php and check the answer.

    So, according to our .htaccess code, if mod_rewrite is active and running on the server, it will return the contents of mod_rewrite_test.txt ie ok , although the test.php file does not exist.

    Otherwise, it will return error 404 - Page not found.

+2
source

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

 echo phpinfo(); 

And access the file in your browser.

0
source

Source: https://habr.com/ru/post/1497760/


All Articles