使用PHP创建没有的.htaccess搜索引擎优化固定链接 [英] Create SEO permalinks using PHP without .htaccess

查看:331
本文介绍了使用PHP创建没有的.htaccess搜索引擎优化固定链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的网页的URL看起来这这样的:

  http://ourdomain.com/articles/?permalink=blah-blah-blah
 

我希望将这些转换为:

  http://ourdomain.com/articles/blah-blah-blah
 

我怎样才能做到这一点使用PHP,但不与htaccess的?

解决方案
  

我怎样才能做到这一点使用PHP,但不与htaccess的。

您不能。您将需要告诉Web服务器如何处理那些不实际存在的URL。在Apache中,即在中央配置或.htaccess文件完成的。

如果你的服务器已经恰巧有 AccepPathInfo在,你可以尝试有像

网址

  http://ourdomain.com/index.php/articles/blah-blah-blah
 

这将重定向到的index.php 文章/等等,夸夸其谈 $ _ SERVER [PATH_INFO] 变量。这种方法被称为穷人的URL重写,因为你无法摆脱的中的index.php 部分中的URL。如果提到的设置已打开(我认为这是在默认情况下),你可能能够做到这一点,而无需使用.htaccess文件。

Currently, my page URLs look this this:

http://ourdomain.com/articles/?permalink=blah-blah-blah

I want to convert these to:

http://ourdomain.com/articles/blah-blah-blah

How can I accomplish this using PHP but not with .htaccess?

解决方案

How can i accomplish this using php but not with .htaccess..

You can't. You will need to tell the web server how to deal with URLs that don't physically exist. In Apache, that is done in the central configuration or in a .htaccess file.

If your server already happens to have AccepPathInfo On, you can try having URLs like

http://ourdomain.com/index.php/articles/blah-blah-blah

which will redirect to index.php and have articles/blah-blah-blah in the $_SERVER["PATH_INFO"] variable. This method is known as "poor man's URL rewriting" because you can't get rid of the index.php part in the URL. If the mentioned setting is turned on (I think it is by default), you may be able to do this without using a .htaccess file.

这篇关于使用PHP创建没有的.htaccess搜索引擎优化固定链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆