简体   繁体   English

如何使用Htaccess重定向到php文件

[英]How Do I redirect to php file with Htaccess

Is there a way to redierct a url to a php file based on one part of the url. 有没有一种方法可以将URL重定向为基于URL一部分的php文件。

For example I have a url - 例如,我有一个网址-

http://www.website.org/Cat/89/Diamond-Wedding-Rings.htm

I will have a few different of these urls. 我将有一些不同的网址。 I wish to redirect all the pages with /Cat/ to a php file which will pull the Id and display the category and products. 我希望将所有带有/ Cat /的页面重定向到一个php文件,该文件将提取ID并显示类别和产品。

in my htaccess I have 在我的htaccess中

RewriteRule ^Cat/([0-9]+)/(.*)\.htm category.php?cat_id=$1&title=$2 [NC,L]

I'm not getting a 404 because the cms system redirects to the homepage if the page is not found. 我没有收到404,因为如果找不到页面,cms系统将重定向到主页。

I'm a complete noob when it comes to htaccess and I'm basing this on some of the existing rules in the htaccess which do something similar. 在htaccess方面,我是一个完全菜鸟,我将它基于htaccess中现有的一些规则进行类似的操作。 I don't really need the title part it's really just the ID. 我真的不需要标题部分,而只是ID。

如果您需要的是ID,则可以使用

RewriteRule ^Cat/([0-9]+)/(.*) category.php?cat_id=$1

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

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