简体   繁体   English

Php 自定义网站重定向。php urls to rewrites urls

[英]Php custom website redirecting .php urls to rewrites urls

What is the best way to redirect.PHP URLs to rewrites URLs.重定向 URL 的最佳方法是什么。PHP URL 以重写 URL。 The rewrites URLs is working perfect.重写 URL 运行良好。 I want if user come or enter URL like /index.php or cart.php etc.. it should redirect to domain.com or /cart. I want if user come or enter URL like /index.php or cart.php etc.. it should redirect to domain.com or /cart.

This is my .htaccess code below for rewriting URLs这是我的 .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>

I am trying to figure out and redirect it to rewrite URLs but facing a issue.我试图弄清楚并将其重定向以重写 URL,但面临一个问题。 I am creating this below code.我在下面的代码中创建这个。

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. But it is also redirecting the ajax.PHP files like /load.php to /load so then the ajax is not working.

I just ignore the load.php file and it is working now.我只是忽略了 load.php 文件,它现在正在工作。

elseif($request_uri["path"] && $uri_to != 'load'){}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM