1
我的.htaccess成功重定向如下:的.htaccess不漂亮的URL
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./backend-scripts/url_parser.php
然后,处理URL重定向是文件url_parser.php这是如下。
<?php
// open file and get its contents in a string format.
$string = file_get_contents("../json/site_map.json");
// decode the json string into an associative array.
$jsonArray = json_decode($string, TRUE);
// add trailing slash to URI if its not there.
$requestURI = $_SERVER['REQUEST_URI'];
$requestURI .= $requestURI[ strlen($requestURI) - 1 ] == "/" ? "" : "/";
// split up the URL at slashes.
$uriArray = explode('/', $requestURI);
// select the last piece of exploded array as key.
$uriKey = $uriArray[count($uriArray)-2];
// lookup the key in sitemap
// retrieve the absolute file URL.
$absPath = $jsonArray[$uriKey];
// reformulate the URL.
$path = "../$absPath";
// include the actual page.
include($path);
?>
为了测试我的PHP代码,我取代
$requestURI = $_SERVER['REQUEST_URI'];
通过如下:
$requestURI = "/welcome";
它完美地工作。所以我很确定我的.htaccess文件里有什么问题。我该如何改变它?
您正在执行模式匹配并捕获请求,但是您不会对其执行任何操作。 –
你能详细说明我应该怎么做?这将非常有帮助。在此先感谢 – Muavia
不清楚什么是你的代码不工作。 – anubhava