.htaccess 在将RedirectMatch从$\u GET url永久重定向到语义url时强制重定向
我正在做一些.htaccess设置来改进语义URL的搜索引擎优化。当前,当您转到语义URL.htaccess 在将RedirectMatch从$\u GET url永久重定向到语义url时强制重定向,.htaccess,.htaccess,我正在做一些.htaccess设置来改进语义URL的搜索引擎优化。当前,当您转到语义URLwww.website.com/profile/exampleusername时,它工作得非常好,尽管我仍然能够访问相同的页面,而不会因为URL中的纯get请求而出现任何红色警报www.website.com/profile?username=exampleusername。 我尝试使用重定向和重定向匹配,但无法使其工作 以下是.htaccess中的相关代码 RewriteCond %{THE_REQUES
www.website.com/profile/exampleusername
时,它工作得非常好,尽管我仍然能够访问相同的页面,而不会因为URL中的纯get请求而出现任何红色警报www.website.com/profile?username=exampleusername
。
我尝试使用重定向和重定向匹配,但无法使其工作
以下是.htaccess中的相关代码
RewriteCond %{THE_REQUEST} /profile\.php\?username=([^\s&]+)&buddy_identifier=([^\s&]+) [NC]
RewriteRule ^profile/%1/%2? [R=302,L]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ profile.php?username=$1&buddy_identifier=$2 [L,NC,QSA]
我希望能够转到www.website.com/profile?username=exampleusername
,然后被重定向到www.website.com/profile/exampleusername
完整。htacces
RewriteEngine on
Options -MultiViews +FollowSymLinks -Indexes
RewriteCond %{ENV:REDIRECT_STATUS} ^$
############# REMOVE FILE EXTENSION #############
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
#####
######## ONLY ACCESS BY HTTPS://WWW.* AND NO EXTENSION #############
#commented bcs of dev workspace localhost
#RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^/]+)\.php(\?|\ |$)
#RewriteRule ^ /%2 [L,R=301]
#RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
#RewriteCond %{HTTPS} off [OR]
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
#RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
############# INDEX RENAME #############
DirectoryIndex gamingbuddy.php
################### SEMANTIC URL ######################
### URL FOR GAMES.PHP ###
RewriteCond %{THE_REQUEST} /games\.php\?game=([^\s&]+)&game_style=([^\s&]+) [NC]
RewriteRule ^games/%1/%2? [R=302,L]
RewriteRule ^games/([^/]+)/([^/]+)/?$ games.php?game=$1&game_style=$2 [L,NC,QSA]
### URL FOR PRIVATE PROFILE ###
RewriteCond %{THE_REQUEST} /profile\.php\?username=([^\s&]+)&buddy_identifier=([^\s&]+)\s [NC]
RewriteRule ^profile/%1/%2? [R=302,L]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ profile.php?username=$1&buddy_identifier=$2 [L,NC,QSA]
您可以使用以下规则:
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} /profile(?:\.php)?\?username=([^\s&]+)\s [NC]
RewriteRule ^ /profile/%1? [R=302,L]
RewriteRule ^profile/([^/]+)/?$ profile.php?username=$1 [L,NC,QSA]
我仍然可以访问www.website.com/profile?username=exampleusername,这是我想要的部分。当您转到www.website.com/profile时,如何重定向到www.website.com/profile/exampleusername?username=exampleusername此规则适用于该重定向。您可以显示您的完整htaccess吗?我现在已经添加了整个。htaccess确定将更新的规则放在
重写引擎下方的行上,然后重新测试