[英]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.