我想从网址中删除文件名,其中网址为:mysite.com/project.php?page=AAA
,此处想删除project.php?page=
。所以我之前通过以下方法从网址中成功删除了另一个文件名,其中网址为:mysite.com/userinfo.php?user=111
并已移除userinfo.php?user=
htaccess的:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ userinfo.php?user=$1 [L,QSA]
但现在我要使用相同的方法删除project.php?page=
。它不起作用。
我试过了:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ project.php?page=$1 [L,QSA]
这是所有htaccess
#Remove php#
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
#Remove Userinfo#
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ userinfo.php?user=$1 [L,QSA]
答案 0 :(得分:1)
要从mysite.com/userinfo.php?user=111重定向到mysite.com/111,只需2行:
RewriteCond %{QUERY_STRING} user=([^?&]+) [NC]
RewriteRule ^userinfo.php$ /%1? [R,L]