mod_重写规则以删除comment.php

mod_重写规则以删除comment.php,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我需要 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?

我需要

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页错误。我有一个单独的comment.php页面,它正在为我做这项工作

 mysite.com/comment.php?id=sasdfkjsfj
我通过$从url获取id,但是现在,如何处理

mysite.com/sasdfkjsfj
重新定向后

还有,我必须对这种URL进行哪些更改

mysite.com/sasdfkjsfj/Url_redirect_option.

我只是想假设您想将
mysite.com/sasdfkjsfj
重定向到
mysite.com/comment.php?id=sasdfkjsfj
;里维尔人将是不寻常的

将以下.htaccess添加到基本web目录或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
重定向到
mysite.com/comment.php?id=sasdfkjsfj
;里维尔人将是不寻常的

将以下.htaccess添加到基本web目录或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>

你是通过
index.php
处理你的评论吗?@ThinkingMonkey不,我有一个单独的页面comment.php。我想要的是,在重定向之后,如何显示之前由mysite.com/comment.php显示的内容?id=sasdfkjsfjAre如果您通过
index.php
?@ThinkingMonkey处理您的评论,不,我有一个单独的页面comment.php。我想要的是,在重定向之后,如何显示之前由mysite.com/comment.php显示的内容?id=sasdfkjsfj