[英]Url rewriting htaccess specific word
我有這個
RewriteRule ^article/?$ articles.php [L]
目前,這兩個選項都適用於以下網址:article?id = 100和article?id = 100 / Manage
但是我想排除一個特定的詞 :文章后管理?id = 100
該網址將被禁止:article?id = 100 / manage
但是article?id = 100還可以
我該如何更改?
我嘗試
RewriteRule ^article/?$/^(Manage) articles.php [L]
#or
RewriteRule ^article/?$/(Manage) articles.php [L,R=404]
但這行不通。 謝謝
這不僅涉及.htaccess文件。 您需要一個PHP函數與.htaccess一起使用
function slug($string, $spaceRepl = "-") {
// Replace "&" char with "and"
$string = str_replace("&", "and", $string);
// Delete any chars but letters, numbers, spaces and _, -
$string = preg_replace("/[^a-zA-Z0-9 _-]/", "", $string);
// Optional: Make the string lowercase
$string = strtolower($string);
// Optional: Delete double spaces
$string = preg_replace("/[ ]+/", " ", $string);
// Replace spaces with replacement
$string = str_replace(" ", $spaceRepl, $string);
return $string;
}
?>
和你的htaccess RewriteEngine上
RewriteRule ^articles/([0-9]+)/([a-zA-Z0-9_-]+) articles.php?id=$1
遵循本教程http://www.simplecss3.com/tutorial/19/how-to-make-a-seo-friendly-url-using-php-and-htaccess
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.