htaccess的配置文件重写帮助 [英] .htaccess profile rewrite help

查看:400
本文介绍了htaccess的配置文件重写帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重写规则1 ^用户/(.*)/(.*)profile.php用户= $&安培; V = $ 2 [L] 工程的 http://10.0.1.5/user/Kevin/wall/

如果我这样做 http://10.0.1.5/user/Kevin/wall 它404的。 如果我做 http://10.0.1.5/user/Kevin/ 它404的 如果我做 http://10.0.1.5/user/Kevin 它404的

if i do http://10.0.1.5/user/Kevin/wall it 404's. if i do http://10.0.1.5/user/Kevin/ it 404's if i do http://10.0.1.5/user/Kevin it 404's

我累了

 RewriteRule ^user/(.*) profile.php?user=$1 [L]
    RewriteRule ^user/(.*) profile.php?user=$1 [L]
    RewriteRule ^user/(.*)/(.*)/ profile.php?user=$1&v=$2 [L]
    RewriteRule ^user/(.*)/(.*) profile.php?user=$1&v=$2 [L]

但它没有工作像我想要的。我想这与所有4个可能的网址工作。我应该怎么办?

But it didn't work like i wanted. I want it to work with all 4 possible urls. What should i do?

推荐答案

使用一个更具体的模式比。* [^ /] + 和使用 / $ 使尾随斜线可选:?

Use a more specific pattern than .* like [^/]+ and use /?$ to make the trailing slash optional:

RewriteRule ^user/([^/]+)/?$ profile.php?user=$1 [L]
RewriteRule ^user/([^/]+)/([^/]+)/?$ profile.php?user=$1&v=$2 [L]

不过,我建议只使用的格式之一(带或不带斜线),删除或添加了结尾的斜线,如果它是present或丢失:

But as I recommend to just use one of the formats (with or without trailing slash), remove or add the trailing slash if it is present or missing:

# remove trailing slash
RewriteRule (.*)/$ /$1 [L,R=301]

# add trailing slash
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule .*[^/]$ /$0/ [L,R=301]

这篇关于htaccess的配置文件重写帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆