[英]Php custom website redirecting .php urls to rewrites urls
重定向 URL 的最佳方法是什么。PHP URL 以重寫 URL。 重寫 URL 運行良好。 I want if user come or enter URL like /index.php or cart.php etc.. it should redirect to domain.com or /cart.
這是我的 .htaccess 代碼,用於重寫 URL
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} baqsa\.pk [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.baqsa.pk/$1 [R,L]
</IfModule>
我試圖弄清楚並將其重定向以重寫 URL,但面臨一個問題。 我在下面的代碼中創建這個。
if(empty($params))
{
$request_uri = parse_url($_SERVER['REQUEST_URI']);
$uri_to = basename($request_uri["path"],'.php');
if($uri_to == 'index')
{
header('Location:'.BASE_URL, true, 301);
}
elseif($request_uri["path"])
{
header('Location:'.$uri_to, true, 301);
}
}
But it is also redirecting the ajax.PHP files like /load.php to /load so then the ajax is not working.
我只是忽略了 load.php 文件,它現在正在工作。
elseif($request_uri["path"] && $uri_to != 'load'){}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.