2012-02-07 123 views
1

我需要有mod_rewrite的規則去除comment.php

mysite.com/comment.php?id=sasdfkjsfj 

重定向到

mysite.com/sasdfkjsfj. 

現在,我使用這個代碼,這樣做

RewriteEngine on 
RewriteBase/

#redirect to remove comment.php 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /comment\.php\?id=([^\ &]+) [NC] 
RewriteRule^%1? [L,R=301] 

#process the SEF Url with comment.php 
RewriteRule ^([-a-zA-Z]+)$ comment.php?id=$1 [L] 

它將url地址更改爲

mysite.com/sasdfkjsfj. 

但這會導致404頁面錯誤。我這是做這項工作的

mysite.com/comment.php?id=sasdfkjsfj 

在那裏我通過$ _GET [「身份證」]從URL獲得ID,但現在一個單獨的頁面comment.php,如何處理

mysite.com/sasdfkjsfj 

重定向後。

而且也什麼樣的變化,我必須讓這種類型的URL

mysite.com/sasdfkjsfj/Url_redirect_option. 
+0

你處理你的通過'index.php'評論? – ThinkingMonkey 2012-02-07 16:57:31

+0

@ThinkingMonkey不,我有一個單獨的頁面comment.php。我想要的是,重定向後如何顯示以前由mysite.com/comment.php?id=sasdfkjsfj顯示的內容 – 2012-02-07 17:11:02

回答

1

我只是要假定要重定向到mysite.com/sasdfkjsfjmysite.com/comment.php?id=sasdfkjsfj;這種敬畏是不尋常的。

添加下面的.htaccess到基礎網絡的目錄,或進入你的Apache配置:

<IfModule mod_rewrite.c> 
RewriteEngine On 
# if you want to use /comment/ as a base dir, as suggested by ThinkingMonkey 
# then you could use this instead 
# RewriteRule ^comment/([a-zA-Z0-9_]+)$ /comment.php?id=$1 [L] 

# look for "mysite.com/anyasciichars" without a . or a/
# the [L] means this is the last rule processed (if it matches) 
RewriteRule ^([a-zA-Z0-9_]+)$ /comment.php?id=$1 [L] 
</IfModule> 

要處理的mysite.com/sasdfkjsfj/rewrite_rule的情況下,做這樣的事情:

<IfModule mod_rewrite.c> 
RewriteEngine On 
# look for "mysite.com/anyasciichars/rewrite_rule" 
# the [L] means this is the last rule processed (if it matches) 
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$ /comment.php?id=$1&rule=$2 [L] 
</IfModule>