簡體   English   中英

URL Mod-重寫

[英]URL Mod-Rewrite

我目前有一個有效的網址:

http://example.com/security-services.php?service=fixed-camera-surveillance

然后我讓PHP說, $_REQUEST['service']做一些事情...

但是,如果URL如下所示,我想實現相同的功能:

http://example.com/security-services/fixed-camera-surveillance

謝謝!

像這樣的.htaccess文件應該可以做到。

Options +FollowSymLinks
RewriteEngine On

RewriteRule security-services/(.*)/? security-services.php?service=$1 [L]

security-services/(.*)/? 匹配瀏覽器中的URL並將其重寫為security-services.php

關鍵部分是(.*) ,它捕獲URL的該部分並將其作為GET值傳遞給PHP腳本。

嘗試以下規則:

RewriteEngine on
RewriteRule ^security-services/([^/]+)$ security-services.php?service=$1 [L]

[^/]+描述了/security-services (…)形成匹配的組,然后可以在替換中使用$1引用的下一個路徑段。

而且,如果您想對任何一種…-service.php文件進行更一般的介紹:

RewriteEngine on
RewriteRule ^([^/-]+)-services/([^/]+)$ $1-services.php?service=$2 [L]

您可以創建如下規則:

RewriteRule ^security-services/(.*)/? /security-services.php?service=$1

如果您使用的是.conf文件,請將^更改為^/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM