我的目录设置如下:
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的问题?
你有什么专业的建议?
答案 0 :(得分:1)
将其放入根.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" />