使用.htaccess从URL中删除index.php和根文件夹中的另一个页面
在我的根文件夹中有使用.htaccess从URL中删除index.php和根文件夹中的另一个页面,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,在我的根文件夹中有index.php和profile.php 目前我正在使用这些规则重写我的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
和profile.php
目前我正在使用这些规则重写我的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,如下所示:
从example.com/profile.php?u=user1
到example.com/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]
如何编辑我的
.htaccess
一起重写profile.php
?基于上述问题和评论,以下是适用于您的规则:
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]
如果请求的URL包含“?”、“&”、“/”、“=”符号,请检入“重写条件”,如果不包含,则将请求重写到profile.php。@Eugeny我不清楚…
index.php
包含这些符号too@anubhava好啊所以在这种情况下没有解决方案?相同的URL/abcd
不能同时由index.php
和profile.php
处理。您必须为profile.php
@anubhava添加前缀,如/u/abc
,谢谢,将example.com/profile.php?u=user1
转换为example.com/profile/user1
(在我当前的.htaccess
)我真的感谢您:)