配置htaccess文件斜线后忽略过去的目录和重定向可变 [英] Configure htaccess file to ignore last directory after slash and redirect with variable

查看:85
本文介绍了配置htaccess文件斜线后忽略过去的目录和重定向可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

www.site.com/your/blue

www.site.com/your/blue

将重定向到... www.site.com/your/index.php?=blue

will redirect to... www.site.com/your/index.php?=blue

当有人类型www.site.com/your/blue它抛出一个错误说的页面不存在现在。 谁能帮助我呢?预先感谢您。

right now when someone types in www.site.com/your/blue it throws an error saying page does not exist. can anyone help me with this? thank you in advance.

推荐答案

mod-rewrite已用于这种重定向:

Mod rewrite has to be used for this kind of redirects:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ $1/index.php?page=$2 [L]
</IfModule>

这正则表达式保证一个干净的URL被传递到网站和作品有或没有结束斜线。

This regex ensures a clean url is being passed to the site and works with or without a ending slash.

注:传递给PHP参数需要有一个名称,所以我加页=

NB: Parameters passed to PHP need to have a name so I added page=

如果你想让它不受任何限制上班(空格将工作)

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^([^/]+)/([^/]+)/?$ $1/index.php?page=$2 [L]
</IfModule>

这篇关于配置htaccess文件斜线后忽略过去的目录和重定向可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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