如何编写Apache重写规则?

时间:2022-11-24 08:22:01

Currently I have URLs like these:

目前我有这样的网址:

http://example.com/d/tag.php?n=1&tag=php
http://example.com/d/tag.php?n=1&tag=cms

I want to add the rewrite rule in .htaccess file.to make the URL like this:

我想在.htaccess文件中添加重写规则。使URL像这样:

http://example.com/tag/1/php

How to write such rule?

怎么写这样的规则?

2 个解决方案

#1


3  

Here you gou:

你在这里:

 RewriteEngine On
 RewriteRule ^tag/([0-9]*)/(.*)$ tag.php?n=$1&tag=$2

Don't forget to put that in your .htaccess file under your direcrory (d).

不要忘记将它放在您的.htaccess文件中(d)。

#2


1  

have a look to this link

看看这个链接

mod_rewrite redirect all the requests linke http://exmple.com/d/tag.php?n=1&tag=php to a specific page there you have to write the code that handle the request

mod_rewrite将所有请求重定向到http://kemple.com/d/tag.php?n=1&tag=php到特定页面,你必须编写处理请求的代码

Hope this helps

希望这可以帮助

#1


3  

Here you gou:

你在这里:

 RewriteEngine On
 RewriteRule ^tag/([0-9]*)/(.*)$ tag.php?n=$1&tag=$2

Don't forget to put that in your .htaccess file under your direcrory (d).

不要忘记将它放在您的.htaccess文件中(d)。

#2


1  

have a look to this link

看看这个链接

mod_rewrite redirect all the requests linke http://exmple.com/d/tag.php?n=1&tag=php to a specific page there you have to write the code that handle the request

mod_rewrite将所有请求重定向到http://kemple.com/d/tag.php?n=1&tag=php到特定页面,你必须编写处理请求的代码

Hope this helps

希望这可以帮助