简体   繁体   English

.htaccess中的隐藏文件扩展名

[英]Hidden File Extensions in .htaccess

I have hidden my file extensions on my website URL and I am wondering if I need to change my links on the other pages. 我在网站URL上隐藏了文件扩展名,我想知道是否需要更改其他页面上的链接。

For example, If I have 'www.example.com/packages', should I then change the links pointing to that page from href="packages.php" to href="packages" since the file extension is now just 'packages' instead of 'packages.php'. 例如,如果我有“ www.example.com/packages”,那么我应该将指向该页面的链接从href =“ packages.php”更改为href =“ packages”,因为文件扩展名现在只是'packages'而不是“ packages.php”。

Is this important to change or would it be better to leave it as-is? 这对改变是否重要还是将其保持原样更好? Which would be better for SEO? 哪个对SEO更好?

Personally, I would whitelist it. 就个人而言,我会将其列入白名单。 RewriteRule ^/(products|about_page|other)/([A-Za-z0-9]+)/?$ /$1.php?param=$2 [L] RewriteRule ^/(products|about_page|other)/?$ /$1.php [L]

This way, you control which files are accessible without the extension (and can even fake a REST router with parameters). 这样,您可以控制无需扩展名即可访问的文件(甚至可以伪造带有参数的REST路由器)。

But to answer your question: Yes. 但要回答您的问题:是的。 If you're going to implement a feature, you should use it. 如果要实现功能,则应使用它。

It is better to have links as href="packages" for SEO purpose. 出于SEO的目的,最好将链接设置为href="packages"

And for the URLs already indexed in search engines use this 301 rule: 对于已经在搜索引擎中建立索引的网址,请使用以下301规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

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

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