首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >搜索引擎优化的Mod_rewrite URL

搜索引擎优化的Mod_rewrite URL
EN

Stack Overflow用户
提问于 2010-11-28 03:01:24
回答 1查看 215关注 0票数 1

我的目录设置如下:

代码语言:javascript
复制
mywebsite/directory1/index.php
mywebsite/directory2/index.php
mywebsite/directory3/index.php
mywebsite/directory4/index.php

这是不友好的搜索引擎优化。如何使用mod_rewrite执行以下操作:

代码语言:javascript
复制
mywebsite/directory1/
mywebsite/directory2/
mywebsite/directory3/

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

你有什么专业的建议?

EN

回答 1

Stack Overflow用户

发布于 2010-11-28 03:06:28

将以下代码放入根.htaccess文件中:

代码语言:javascript
复制
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:

代码语言:javascript
复制
var_dump($_SERVER['REQUEST_URI']);

或者您可以使用$_GET‘’path‘

代码语言:javascript
复制
var_dump($_GET['path']);

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

代码语言:javascript
复制
<img src="/image/image.jpg" alt="image" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4293333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档