簡體   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