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 页面错误。我有一个单独的 comment.php 页面,它负责
mysite.com/comment.php?id=sasdfkjsfj
通过 $_GET['id'] 从 url 获取 id,但现在如何
mysite.com/sasdfkjsfj
在重定向后处理。
还有我必须对这种类型的 URL 进行哪些更改
mysite.com/sasdfkjsfj/Url_redirect_option.
I need to have
mysite.com/comment.php?id=sasdfkjsfj
redirected to
mysite.com/sasdfkjsfj.
Right now, i'm using this code for doing that
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]
It changes the url address to
mysite.com/sasdfkjsfj.
but that results a 404 page error. I have a separate comment.php page which is doing the job for
mysite.com/comment.php?id=sasdfkjsfj
where i get the id by $_GET['id'] from the url but now, how to handle
mysite.com/sasdfkjsfj
after redirection.
And also what changes i have to make for this type of URL
mysite.com/sasdfkjsfj/Url_redirect_option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您想将
mysite.com/sasdfkjsfj
重定向到mysite.com/comment.php?id=sasdfkjsfj
;相反的情况会很不寻常。将以下 .htaccess 添加到基本 Web 目录或 apache 配置中:
要处理
mysite.com/sasdfkjsfj/rewrite_rule
的情况,请执行以下操作:I'm just going to presume you want to redirect
mysite.com/sasdfkjsfj
tomysite.com/comment.php?id=sasdfkjsfj
; the reverese would be unusual.Add the following .htaccess into the base web directory, or into your apache config:
To handle the case of
mysite.com/sasdfkjsfj/rewrite_rule
, do something like this: