开发者

How would my web page examples look like before mod rewrite when using PHP

开发者 https://www.devze.com 2023-01-10 11:46 出处:网络
I want to display all my tags on one web page for example, www.example.com/tags/ and then when some one

I want to display all my tags on one web page for example, www.example.com/tags/ and then when some one clicks on one of the tags I want to disp开发者_高级运维lay all the posts related to that tag on another web page for example, www.example.com/tags/clicked-tag/ how would I be able to do this since it really would not be a good idea to create a web page for each tag?

I will be creating an index.php page for the tags folder www.example.com/tags/.

But how would I be able to display the posts related to that tag on another page for example, www.example.com/tags/clicked-tag/?


Mod_rewrite for generating get variable in "nice" form

You have to add mysql field called "tag" or something


One possibility is to use a rewrite rule. Create a PHP file named say "details.php" inside the tag folder.

Then, in httpd.conf:

RewriteRule /tags/([^/]+)/?$ /tags/details.php?tag=$1 [B,L]

or, if you must, in a .htaccess file inside /tags:

RewriteCond $1 !=details.php
RewriteRule ([^/]+)/?$ details.php?tag=$1 [B]

Another possibility would be to activate the option MultiViews and serve all requests to /tags/* from a file named tags.php in the root (using the path info to determine what to show).


Am I missing something here? You seem to want to display all posts for a given tag <my_tag> on the page www.example.com/tags/clicked-tag.php?

So, can't your tags link to www.example.com/tags/clicked-tag?tag=<tag_name>, where <tag_name> is different for each tag, obviously, and then www.example.com/tags/clicked-tag.php simply look at a variable $_GET["tag"]?

That seems the way to do it in PHP, but since others are giving rewrite answers I fear that I may have misunderstood the question. If so, maybe you could clarify?


i want all the tags to have their own unique file name like www.example.com/tags/tag1 www.example.com/tags/tag2 www.example.com/tags/tag3 and so on - thanks for the clarification.

How about ... mmmm ... all links on the first page lead to an intermediate page which the user will never see ... www.example.com/tags/clicked-tag.php for example, and that does something like

   if file www.example.com/tags/<tag> not exists then crete it  
   header("Location: www.example.com/tags/<tag>");

and each page includes a common file with a function which takes as a paramater and build the output page ...

That would do it, wouldn't it?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号