简体   繁体   English

如何通过硬编码链接应用.htaccess或PHP替代使用SEO URL

[英]How to apply .htaccess with hardcoded link or alternative for PHP to use SEO URL

I am coding website in PHP 我正在用PHP编码网站

And My links are :- 我的链接是:-

http://example.com/science.php?category=alien&title=Find+UFO+Just+over+your+head+by+clicking+here http://example.com/science.php?category=alien&title=Find+UFO+Just+over+your+head+by+click+here

Now, I want to show url in my view source as :- 现在,我想在我的视图源中显示网址为:-

http://example.com/science.php/alien/Find+UFO+Just+over+your+head+by+clicking+here http://example.com/science.php/alien/Find+UFO+Just+over+your+head+by+click+here

Also i want this as working link :- 我也希望这是工作链接:-

From .htaccess [with the help of generateit.net > mod_rewrite generator] here is the code:- 来自.htaccess [在generateit.net> mod_rewrite生成器的帮助下]的代码是:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /science.php?category=$1&title=$2 [L]

Now what do i need to do in PHP , to make this URL Valid. 现在,我需要在PHP中做什么以使此URL有效。

Do i need to write below link :- 我需要在下面的链接中写:-

<a href="http://example.com/science.php?category=<?php echo $rows['category'] ?>&title=<?php echo htmlentities($rows['title']); ?>" > <?php echo $rows['title'] ?></a>

in my code or do i need to write :- 在我的代码中还是我需要写:-

<a href="http://example.com/science.php/<?php echo $rows['category'] ?>/<?php echo htmlentities($rows['title']); ?>" > <?php echo $rows['title'] ?></a>

or some function to make above url. 或一些使上述网址起作用的功能。

Thank you ! 谢谢 ! I am hunting for this knowledge since long time. 我一直在寻找这种知识。

Thanks once again 再次感谢

Actually, there is no need for any change from PHP Side, because php will receive request after translated by .httaccess file. 实际上,不需要从PHP Side进行任何更改,因为php在经过.httaccess文件转换后将收到请求。

Now i think there is something wrong with your .httaccess conditions, please try below code: 现在,我认为您的.httaccess条件有问题,请尝试以下代码:

RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /$1.php?category=$2&title=$3 [L]

and after save, try link below 保存后,请尝试下面的链接

http://example.com/science/alien/Find+UFO+Just+over+your+head+by+clicking+here

I hope this help 我希望这个帮助

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

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