English 中文(简体)
全球重写规则
原标题:Htaccess global RewriteRule

我不知道该如何解释这个问题,所以标题有点模糊!

我开始在网站上的图片/图片页面上工作,一切都很好。但是我想添加下一个/以前的图片功能,就像任何好的图片网站一样。我想通过不同的选项,按照变量来分类相册。

现在图片上的url是 http://localhost/photo/174/picture-name/ ,我想在此添加一些参数,使url看起来像http://localhost/photo/174/picture-name/album:5/sort:name/

在.htaccess的帮助下,我想提取变量 album sort'。 `但是,我仍然希望能够到达网页,只有这个url http://localhost/photo/174/picture-name/"。

现在,我的.htaccess文件 看起来像这个:

RewriteEngine on

RewriteRule ^photo/([A-Za-z0-9]+)/(.*)/$ photo.php?pic_id=$1

我试着把这条线加进去 但没有成功

RewriteRule ^(.*)/album:([A-Za-z0-9]+)/sort:([A-Za-z0-9]+)/$ &album=$2&sort=$3

我希望有人能给我一个答案

祝你今天过得愉快

约 里斯

最佳回答

你的意思是这样的吗?

RewriteRule ^photo/([A-Za-z0-9]+)/[^/]+/album:([A-Za-z0-9]+)/sort:([A-Za-z0-9]+)/$ photo.php?pic_id=$1&album=$2&sort=$3

您也需要改变您原来的规则 :

RewriteRule ^photo/([A-Za-z0-9]+)/([^/]*)/?$ photo.php?pic_id=$1

因为你拥有的东西 将会与URI和参数相匹配

问题回答

我猜你是在说这个,而你的例子是不正确的:

RewriteRule ^photo/(.*)/.*/album:(.*)/sort:(.*)/$ photo.php?pic_id=$1&album=$2&sort=$3

(为了简单起见,我替换了一些表达式)。

这里, < a href=" "http://mydomain.com/photo/174/picture-name/album:5/sort:name/" rel="nofollow" >http://mydomain.com/photo/174/picture-name/album:5/sort:name/ 重新写到





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...