यहां राउटर है जो मैं बिल्टिन PHP वेबसर्वर के लिए उपयोग करता हूं जो फाइल सिस्टम से संपत्तियों की सेवा करता है और अन्यथा index.php फ़ाइल में पुनर्लेखन करता है।
रन का उपयोग:
php -S localhost:8080 router.php
router.php:
<?php
chdir(__DIR__);
$filePath = realpath(ltrim($_SERVER["REQUEST_URI"], '/'));
if ($filePath && is_dir($filePath)){
// attempt to find an index file
foreach (['index.php', 'index.html'] as $indexFile){
if ($filePath = realpath($filePath . DIRECTORY_SEPARATOR . $indexFile)){
break;
}
}
}
if ($filePath && is_file($filePath)) {
// 1. check that file is not outside of this directory for security
// 2. check for circular reference to router.php
// 3. don't serve dotfiles
if (strpos($filePath, __DIR__ . DIRECTORY_SEPARATOR) === 0 &&
$filePath != __DIR__ . DIRECTORY_SEPARATOR . 'router.php' &&
substr(basename($filePath), 0, 1) != '.'
) {
if (strtolower(substr($filePath, -4)) == '.php') {
// php file; serve through interpreter
include $filePath;
} else {
// asset file; serve from filesystem
return false;
}
} else {
// disallowed file
header("HTTP/1.1 404 Not Found");
echo "404 Not Found";
}
} else {
// rewrite to our index file
include __DIR__ . DIRECTORY_SEPARATOR . 'index.php';
}
'php -S' एपाचे नहीं है, क्यों चाहिए यह किसी भी अपाचे config फ़ाइलों को पढ़ने के लिए? –
आप अपने 'फ्रंट कंट्रोलर' को 'php -S ... सर्वर/index.php' –
द्वारा सर्वर पर सर्वर से कहने के लिए कह सकते हैं, लेकिन .htaccess फ़ाइलों का उपयोग आमतौर पर अनुप्रयोगों में किया जाता है, इसलिए मुझे आश्चर्य हुआ कि क्या सभी PHP सर्वर ने उन्हें संभाला था। मुझे नहीं लगता। एक फ्रंट कंट्रोलर को इंगित करना ठीक है, लेकिन जब मैं वर्तमान में कुछ/न्यूज़/व्यू/205 यूआरएल लिखना चाहता हूं तो मैं नहीं कर सकता। – Martyn