How to check if mod_rewrite is enabled in php?
If you're using mod_php, you can use apache_get_modules()
. This will return an array of all enabled modules, so to check if mod_rewrite
is enabled, you could simply do
in_array('mod_rewrite', apache_get_modules());
Unfortunately, you're most likely trying to do this with CGI, which makes it a little bit more difficult.
You can test it using the following, though
strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false
If the above condition evaluates to true
, then mod_write
is enabled.
How to enable mod_rewrite on Apache 2.4?
I found the way to know if a module is loaded or not, here's to command to list the modules enabled:
apachectl -M | sort
It will list all enabled modules alphabetically.
Wordpress has an .htaccess but default where it enables rewrite_module
for its use:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The only thing that i had to do was add this to the vhost.conf file at /etc/httpd/conf.d/vhosts.conf
<Directory /var/www/mysite>
Options Indexes FollowSymLinks
Require all granted
AllowOverride All
</Directory>
That's because I'm handling my hosts in that file. But it could be done at httpd.conf
, or any other .conf
file that is Included to the httpd.conf
Thanks...
why isn't my mod_rewrite working even when it is enabled?
Please change the conf as below to allow the access in your /etc/apache2/sites-available
or /etc/httpd/conf.d/
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
Related Topics
How to Get Count of Rows in MySQL Table Using PHP
Max Size of Url Parameters in _Get
Laravel 5.2 Validation Error Not Appearing in Blade
Convert Flat Array to a Delimited String to Be Saved in the Database
How to Run a .Bat File from PHP
A Non Well Formed Numeric Value Encountered
I Have an Array of Integers, How to Use Each One in a MySQL Query (In PHP)
Insert/Update Helper Function Using Pdo
PHP Function to Make Slug (Url String)
Correct Way to Use Like '%{$Var}%' With Prepared Statements
Preparing For Removal of Mcrypt in PHP 7.2
Performance of For VS Foreach in PHP
Convert Command Line Curl to PHP Curl
How to Generate All Permutations of a String in PHP