简体   繁体   English

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

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

I modified it according to your suggestion 我根据你的建议修改了它

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

now, I get /leagues/pl/xxxxxx as the new url 现在,我将/ leagues / pl / xxxxxx作为新网址

however, it does not find the page, displaying File not found (404 error) 但是,它找不到页面,显示找不到文件(404错误)

This is my entire .htaccess file 这是我的整个.htaccess文件

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

In my previous example I used 'pl' instead of $rs['ext'] to make it easier to explain. 在我之前的例子中,我使用'pl'而不是$ rs ['ext']来更容易解释。 Also, I don't know how to use variables in .htaccess 另外,我不知道如何在.htaccess中使用变量

I would immensely appreciate if you could show me how to use preg_replace or any other relevant function so that my code would look and work something like 如果您能告诉我如何使用preg_replace或任何其他相关功能以便我的代码看起来和工作类似,我将非常感激。

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

and the url display something like 并且网址显示类似的内容

/leagues/pl/xxxxxx /联赛/ PL / XXXXXX

pl being the variable pl是变量

with the help of .htaccess 在.htaccess的帮助下

Using my .htaccess as an example: 以我的.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]

The requesthandler.php uses the $_SERVER['REQUEST_URI'] to retrieve the requested data from either database or filesystem. requesthandler.php使用$ _SERVER ['REQUEST_URI']从数据库或文件系统中检索所请求的数据。

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

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