[英]Apache PHP mod_rewrite not working
I'm trying to test out the mod_rewrite meaning: I have two files: level1.php and warpzone.php . 我正在尝试测试mod_rewrite的含义:我有两个文件: level1.php和warpzone.php 。
In my .htaccess I have the following code: 在我的.htaccess文件中,我有以下代码:
RewriteEngine On
RewriteRule ^warp-zone.php$ level-1.php
Yet when I go to warpzone.php, nothing happens :/ (the url doesn't change) 但是,当我转到warpzone.php时,什么也没发生:/(URL不变)
Any suggestions? 有什么建议么? I really don't know what I'm doing wrong.
我真的不知道我在做什么错。
First of all you have dashes in php file names at your .htaccess file, while your files does not have them. 首先,您的.htaccess文件中的php文件名中包含破折号,而文件中没有破折号。
Rewrite conditions - this changes the content to new one, but URL stays as it was: 重写条件-这会将内容更改为新内容,但URL保持不变:
RewriteEngine On
RewriteRule ^warpzone\.php$ level1.php [L]
Redirect conditions - this changes both content and URL to new one: 重定向条件-这会将内容和URL都更改为新的条件:
RewriteEngine On
RewriteRule ^warpzone\.php$ /level1.php [R]
Also you can use Redirect condition instead of mod_rewrite: 您也可以使用重定向条件代替mod_rewrite:
Redirect 301 /warpzone.php /level1.php
In case if it does not work for you, you can use headers() method at the top of your warpzone.php
file: 如果它对您不起作用,则可以在
warpzone.php
文件顶部使用headers()方法:
<?php
header("Location: " . $_SERVER['SERVER_NAME'] . "/level1.php");
?>
regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.