Php 从子目录重写页面
我有以下设置:Php 从子目录重写页面,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有以下设置: index.php config.php pages/ index.php about.php contact.php 当我想访问“about.php”时,我需要访问 现在我想重写URL,使其看起来像这样: .htaccess应该是什么样子?我是一个完全不懂修改的人。这应该适合你: RewriteEngine On #External redirect with THE_REQUEST trick; change R to R=301 whe
index.php
config.php
pages/
index.php
about.php
contact.php
当我想访问“about.php”时,我需要访问
现在我想重写URL,使其看起来像这样:
.htaccess应该是什么样子?我是一个完全不懂修改的人。这应该适合你:
RewriteEngine On
#External redirect with THE_REQUEST trick; change R to R=301 when everything works correctly
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?page=(.*)\ HTTP
RewriteRule ^ /%2.php\? [R=302,L]
#Internal rewrite
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*).php$ /index.php?page=$1 [L]
如果您访问
http://example.com/index.php?page=about
它会将您重定向到http://example.com/about.php
我尝试了“重写规则^pages/([^/]*)\.php$?page=$1[L]”之类的方法。谢谢,效果不错!但是现在错误文档404不再工作了。当我访问一个以.php结尾的不存在的页面时,我会看到一个白色的站点。当不存在的页面不是以.php结尾时,一切正常。是否有许多页面需要使用上述代码重定向?然后您可能需要在index.php
文件中执行此操作,检查重定向文件是否存在。如果它不使用类似header('Location:http://example.com/linktoerrordocument');代码>