gpt4 book ai didi

apache - 用于 SEO 的 Mod_rewrite URL

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:35:38 27 4
gpt4 key购买 nike

我的目录设置如下:

mywebsite/directory1/index.php
mywebsite/directory2/index.php
mywebsite/directory3/index.php
mywebsite/directory4/index.php

这对 SEO 不友好。我如何使用 mod_rewrite 执行以下操作:

mywebsite/directory1/
mywebsite/directory2/
mywebsite/directory3/

如何让搜索引擎抓取我的网站而不会有多个 index.php 的问题?

你有什么专业建议?

最佳答案

将其放入您的根 .htaccess 文件中:

RewriteEngine On
#if your index.php is located in the root folder:
RewriteBase /
#or use that, if the path for your index.php is '/some/subfolder/index.php':
#RewriteBase /some/subfolder/

#rewriting only if the request file doesn't exists (you don't want to rewrite request for images or other existing files)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)? index.php?path=$1 [L]

之后,您可以在根 index.php 文件中使用 REQUEST_URI:

var_dump($_SERVER['REQUEST_URI']);

或者你可以使用 $_GET['path']:

var_dump($_GET['path']);

在您的 HTML 和 CSS 中,对图像和其他资源使用绝对路径(或者最好使用完整的 URL):

<img src="/image/image.jpg" alt="image" />

关于apache - 用于 SEO 的 Mod_rewrite URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4293333/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com