繁体   English   中英

如何使用preg_replace和htaccess来修改url?

[英]How to use preg_replace and htaccess to modify url?

我根据你的建议修改了它

<a class="upheader" href="leagues/' . $rs['ext'] . '/' . $rs['uniqueid'] . '" target="_blank">' . $rs['title'] . '</a>

现在,我将/ leagues / pl / xxxxxx作为新网址

但是,它找不到页面,显示找不到文件(404错误)

这是我的整个.htaccess文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule leagues/pl/([0-9]+)/?$ pl?uniqueid=$1 [L]

在我之前的例子中,我使用'pl'而不是$ rs ['ext']来更容易解释。 另外,我不知道如何在.htaccess中使用变量

如果您能告诉我如何使用preg_replace或任何其他相关功能以便我的代码看起来和工作类似,我将非常感激。

<a class="upheader" href="leagues/' . $rs['ext'] . '/' . preg_replace('/\s\s+/', $rs['uniqueid']) . '" target="_blank">' . $rs['title'] . '</a>

并且网址显示类似的内容

/联赛/ PL / XXXXXX

pl是变量

在.htaccess的帮助下

以我的.htaccess为例:

# Rewrites
RewriteEngine           On

# every html-element that uses a src="" needs these:
RewriteCond             %{REQUEST_URI}          ^/styles/.*$
RewriteRule             ^styles\/(.*)           /sites/%{SERVER_NAME}/styles/$1         [L]

RewriteCond             %{REQUEST_URI}          ^/includes/.*$
RewriteRule             ^includes\/(.*)         /sites/%{SERVER_NAME}/includes/$1       [L]

RewriteCond             %{REQUEST_URI}          ^/images/.*$
RewriteRule             ^images\/(.*)           /sites/%{SERVER_NAME}/images/$1         [L]

# everything else will be directed to the requesthandler:
RewriteCond             %{REQUEST_URI}          !^/core/libraries/FCKeditor/.*$
RewriteCond             %{REQUEST_URI}          !/cache/.*$
RewriteCond             %{REQUEST_URI}          !/images/.*$
RewriteCond             %{REQUEST_URI}          !/styles/.*$
RewriteCond             %{REQUEST_URI}          !/includes/.*$
RewriteCond             %{REQUEST_URI}          !^/requesthandler.php
RewriteRule             (.*)                    /requesthandler.php                     [L]

requesthandler.php使用$ _SERVER ['REQUEST_URI']从数据库或文件系统中检索所请求的数据。

暂无
暂无

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

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