![](/img/trans.png)
[英]Redirect url with/without .php extension to index.php using htaccess
[英]Write .htaccess file to redirect url through index.php without the error object not found
這是我的 index.php 文件。
<?php
$url=getCurrentURL();
$path=parse_url($url, PHP_URL_PATH);
$a= str_replace('/', '', $path);
echo $a;
function getCurrentURL()
{
$currentURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$currentURL .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$currentURL .= ":".$_SERVER["SERVER_PORT"];
}
$currentURL .= $_SERVER["REQUEST_URI"];
return $currentURL;
}
?
我實際上是由 xampp 托管的。我的要求是我想要打印 url 路徑。 例如。我把它托管為 www.salary.dev。如果我輸入 www.salary.dev/ibm,我希望 ibm 被打印出來。但是當我輸入這個時,我收到了 404 錯誤。然后我知道我們想要為此編寫 .htaccess 文件。我不知道如何編寫。請幫助我編寫不存在的路由的 .htaccess 文件。請幫助我。提前致謝。
Mod重寫應該有幫助。
.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
嘗試一下
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?action=$1 [L]
索引.php
<?php
echo $_REQUEST['action'];
?>
嘗試這個:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.