简体   繁体   English

php中的友好URL? 其他页面在htaccess中读取更多内容

[英]Friendly URL in php? With other pages readmore in htaccess

I have 2 pages in selecting data from mysql. 我有两页从mysql中选择数据。 First page - readmore.php, to get posts with url from table posts. 第一页 - readmore.php,从表格帖子获取带有url帖子。 Second page - categories.php to get data with caturl from table categories. 第二页 - categories.php从表类别中获取caturl数据。

readmore.php in .htaccess .htaccess中的readmore.php

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9-/]+).html$ readmore.php?url=$1
    RewriteRule ^([a-zA-Z0-9-/]+).html/$ readmore.php?url=$1

categories.php in .htaccess 在.htaccess中的categories.php

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9-/]+).html$ categories.php?caturl=$1
    RewriteRule ^([a-zA-Z0-9-/]+).html/$ categories.php?caturl=$1

My problem located when get caturl htaccess redirects me to readmore.php but I want redirect to categories.php 我的问题位于获取caturl htaccess时将我重定向到readmore.php,但我想重定向到categories.php

You are redirecting *.html to a new url readmore.php?url=* therefor the url changes. 您正在将* .html重定向到新网址readmore.php?url=*因此网址会发生变化。 Since the url is now readmore.php?url=* the second set of rules won't fire (there is no longer a pattern that matches *.html). 由于url现在是readmore.php?url=*第二组规则不会触发(不再存在与* .html匹配的模式)。

Therefor categories will never be loaded. 因此永远不会加载类别。 You will need to add a parameter in your url to distinguish the different types. 您需要在网址中添加一个参数来区分不同的类型。

So make sure all your articles (or categories) have a common part in the url to indicate it is an page of that type. 因此,请确保您的所有文章(或类别)在网址中都有一个共同部分,以表明它是该类型的网页。

Example: 例:

RewriteRule ^article_([a-zA-Z0-9-/]+).html$ readmore.php?url=$1
RewriteRule ^cat_([a-zA-Z0-9-/]+).html$ categories.php?caturl=$1

So an article that was called article_firstpost.html would link to readmore.php?url=firstpost and cat_cars.html would link to categories.php?caturl=cars 所以一篇名为article_firstpost.html的文章会链接到readmore.php?url=firstpostcat_cars.html会链接到categories.php?caturl=cars

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

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