mod_rewrite가 서버에서 활성화되었는지 확인하는 방법은 무엇입니까?
현재 저는 lightspeed 서버 와 함께 호스팅을 사용하고 있습니다. 호스팅 mod_rewrite
이 활성화되어 있지만 스크립트가 작동하지 않습니다. URL에 액세스하려고 할 때마다 404-not found page가 반환 됩니다.
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]
그러나 같은 결과.
mod_rewrite 모듈이 활성화되어 있는지 확인하려면 WAMP 서버의 루트 폴더에 새 php 파일을 만듭니다. 다음을 입력
phpinfo();
브라우저에서 생성 된 파일에 액세스합니다.
CtrlF검색을 엽니 다. 'mod_rewrite'를 검색합니다. 활성화 된 경우 '로드 된 모듈'로 표시됩니다.
그렇지 않은 경우 httpd.conf (Apache Config 파일)를 열고 다음 줄을 찾습니다.
#LoadModule rewrite_module modules/mod_rewrite.so
시작 부분에서 파운드 ( '#') 기호를 제거하고이 파일을 저장하십시오.
아파치 서버를 다시 시작하십시오.
브라우저에서 동일한 PHP 파일에 액세스하십시오.
'mod_rewrite'를 다시 검색하십시오. 지금 찾을 수있을 것입니다.
명령 줄에서 다음을 입력합니다.
sudo a2enmod 재 작성
다시 쓰기 모드가 이미 활성화되어있는 경우이를 알려줍니다!
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>
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!"; ?>
console:
<VirtualHost *:80>
...
<Directory ...>
AllowOverride All
</Directory>
</VirtualHost>
sudo a2enmod rewrite
sudo service apache2 restart
If
in_array('mod_rewrite', apache_get_modules())
returns true
then mod-rewrite is enabled.
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.
you can do it on terminal, either:
apachectl -M
apache2ctl -M
taken from 2daygeek
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.
This works on CentOS:
$ sudo httpd -M |grep rewrite_module
Should output rewrite_module (shared)
You can use php function
apache_get_modules
and check for mod_rewrite
<pre>
<?php
print_r(apache_get_modules());
?>
</pre>
http://in2.php.net/apache_get_modules
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
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
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";
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>
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 #
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.
참고URL : https://stackoverflow.com/questions/7337724/how-to-check-whether-mod-rewrite-is-enable-on-server
'development' 카테고리의 다른 글
Fabric에서 SSH 키 파일 사용 (0) | 2020.08.27 |
---|---|
jquery / javascript를 통해 추가하는 방법은 무엇입니까? (0) | 2020.08.27 |
ID 대신 이름으로 요소 값을 가져 오는 방법 (0) | 2020.08.27 |
프로그래밍 방식으로 iPhone 키보드 위에 도구 모음 정렬 (0) | 2020.08.27 |
클래스 파일의 바이트 코드를 볼 수 있습니까? (0) | 2020.08.26 |