如何创建 SEO 友好的 URL 来合并 PHP 变量/代码段?
我有以下 PHP 代码,它是一个文件名,我将其用作我提供给查看者的每次下载的页面标题。我希望能够拥有 SEO 友好的标题和 URL。
<?php echo $file_info[21]; ?>
每个页面的 URL 看起来与此类似:
http://site.com/directory/download_interim_finder.php?it=ZWtkaW1rcmInbn1ma3h9aXFLcHN6fWVzeDgnISJoO3tran0reW97cSd1YHR5YHZIbWBmfzxwY3tiOnxycnA8Y25zfWpna3Y+YXtlZnl7dnJLf3J8cWd2fT4kJCIramFbcm1tbWRqdHJmJnR2ZGhKd3JpdShQdGV+bX09fWh0b2JnfXx9anV2J3F7YHh4d3Z2S3Jyf3ZmdX8pNyg1anZ/bnhpdGJwVnx5cXF5Zn5bYW14cHp2bTQiKXFsYw==
我想将这个长 URL 转换为对 SEO 更友好的内容,并将我上面指定的 php 代码合并为“filename.php”之类的内容,而不是长 URL你看这里。
我希望使用 .htaccess 但我读到你不能通过那里做到这一点。我花了几个小时寻找解决此问题的方法,但找不到解决方案。任何帮助将不胜感激。
谢谢!
I have the following PHP code which is a file name I'm using as the title of my pages for each download I provide to viewers. I want to be able to have SEO-friendly titles and URLs.
<?php echo $file_info[21]; ?>
The URLs of each page look similar to this:
http://site.com/directory/download_interim_finder.php?it=ZWtkaW1rcmInbn1ma3h9aXFLcHN6fWVzeDgnISJoO3tran0reW97cSd1YHR5YHZIbWBmfzxwY3tiOnxycnA8Y25zfWpna3Y+YXtlZnl7dnJLf3J8cWd2fT4kJCIramFbcm1tbWRqdHJmJnR2ZGhKd3JpdShQdGV+bX09fWh0b2JnfXx9anV2J3F7YHh4d3Z2S3Jyf3ZmdX8pNyg1anZ/bnhpdGJwVnx5cXF5Zn5bYW14cHp2bTQiKXFsYw==
I would like to convert this long URL to something a little more SEO-friendly and that will incorporate the php code I have specified above to something like "filename.php" instead of the long URL you see here.
I was hoping to use .htaccess but I've read that you can't do it through there. I've spent hours looking for ways to fix this and can't find a solution. Any help would be appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关使用 PHP 和 .htaccess mod 重定向创建具有动态内容的 SEO 友好 URL 的分步说明。友好的 URL 可以提高您网站的搜索引擎排名。在尝试此操作之前,您必须在 httpd.conf 中启用 mod_rewrite.so 模块。只需几行 PHP 代码即可将标题数据转换为干净的 URL 格式,非常简单。
数据库
示例数据库博客表列 id、标题、正文和 url。
Publish.php
包含 PHP 代码。将标题文本转换为友好的 URL 格式并存储到博客表中。
Article.php
包含 HTML 和 PHP 代码。显示博客表中的内容。
.htaccess
URL重写文件。将原始 URL 9lessons.info/article.php?url=test.html 重定向到 9lessons.info/test.html
Step By Step instruction about create SEO friendly URL with dynamic content using PHP and .htaccess mod redirection. Friendly URLs improves your site search engines ranking. Before trying this you have to enable mod_rewrite.so module at httpd.conf. It’s simple just few lines of PHP code converting title data to clean URL format.
Database
Sample database blog table columns id, title, body and url.
Publish.php
Contains PHP code. Converting title text to friendly url formate and storing into blog table.
Article.php
Contains HTML and PHP code. Displaying content from blog table.
.htaccess
URL rewriting file. Redirecting original URL 9lessons.info/article.php?url=test.html to 9lessons.info/test.html
当我查看您发布的 URL 示例时,我看到两件事:
/directory/download_interim_finder.php
我猜测您的下载脚本输入是在 it-argument 字符串中编码的,您需要将其放入 URL 中否则您无法识别要下载的文件。由于您希望 URL 具有语义,因此必须将语义信息添加到 URL 中。
例如,您可以制作如下 URL:
在您的 .htaccess 中,您需要规则:
如果您的主机不允许您使用 .htaccess,那么您就不能轻松地使用语义 url。
When I look at the URL example you posted I see two things:
/directory/download_interim_finder.php
I'm guessing your input for the download script is encoded in it-argument string, you will need to put this in the URL else you cant identify which file you want to download. Since you want your URLs to be semantic you have to add your semantic information to the URL.
You could for instance make URLs like:
In your .htaccess you then need the rule:
If your host does not allow you to use .htaccess then you can not easily imploy semantic urls.