Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess以重写原始URL_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php htaccess以重写原始URL

Php htaccess以重写原始URL,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我正在为我的网站创建SEO友好的URL。我有一个文件notfound.php,我将所有URL重定向到该文件。现在,我希望notfound.php在数据库中搜索URL并生成相应的内容 但问题是,在它显示的URL中http://some_url/notfound.php 我不希望此URL显示在地址栏中,而是希望原始URL 比如说, http://some_url/hello/world 正在重定向到http://some_url/notfound.php 使用errordocument404 并且n

我正在为我的网站创建SEO友好的URL。我有一个文件notfound.php,我将所有URL重定向到该文件。现在,我希望notfound.php在数据库中搜索URL并生成相应的内容

但问题是,在它显示的URL中http://some_url/notfound.php 我不希望此URL显示在地址栏中,而是希望原始URL

比如说,

http://some_url/hello/world 正在重定向到http://some_url/notfound.php 使用errordocument404 并且notfound.php正在为内容提供服务


但如何表现呢http://some_url/hello/world 在URL中而不是在notfound.php中?而且,这是在匹配数据库URL时重定向和重写的正确方法吗?

您必须启用mod_rewrite,然后可以尝试:

RewriteEngine on    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ notfound.php [L]

前两行确保您仍然可以加载可能需要的js和css文件等现有文件

ErrorDocument在提供完整URL时执行外部重定向。文档告诉您如何进行内部重定向


什么配置正在进行重定向?另外,如果你没有为一个明显缺失的页面/blah/123/blah/234.txt提供404响应,我相信这会影响你的排名。我正在使用我根文件夹中的.htaccess文件进行重定向。你能发布实际的重定向配置吗?np,很高兴能帮助你谢谢,我在使用外部重定向。我把它改成了内部的。