使用.htaccess从URL中删除index.php和根文件夹内的另一个页面 [英] Removing index.php and another page inside the root folder from URL with .htaccess

查看:68
本文介绍了使用.htaccess从URL中删除index.php和根文件夹内的另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的根文件夹中,有 index.php profile.php

In my Root folder I have index.php and profile.php.

当前,我正在使用这些规则来重写 index.php

Currently I'm using these rules for rewrite my index.php

example.com/index.php?a=profile&u=user1 example.com/profile&u= user1

RewriteEngine On
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$  index.php?a=$1&q=$3     [L]
RewriteRule ^welcome/([^/]+)/?$         index.php?a=welcome             [NC]
RewriteRule ^page/([^/]+)/?$            index.php?a=page&filter=$1      [NC]

效果很好,但现在我也想重写profile.php页面的URL,如下所示:

It works fine but now I want to rewrite my URL for profile.php page too, like this:

来自 example.com/profile。 php?u = user1 example.com/user1

如何编辑我的 .htaccess 一起重写 profile.php

How can I edit my .htaccess to rewrite profile.php together?

推荐答案

根据上面的问题和评论,这里是他的规则应该对您有用:

Based on question and comments above here are the rules that should work for you:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^profile/([^/]+)/?$ profile.php?u=$1 [NC,QSA,L]

RewriteRule ^welcome/([^/]+)/?$ index.php?a=welcome&filter=$1 [NC,QSA,L]

RewriteRule ^page/([^/]+)/?$ index.php?a=page&filter=$1 [NC,QSA,L]

RewriteRule ^(([^/]+)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L,QSA]

这篇关于使用.htaccess从URL中删除index.php和根文件夹内的另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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