Force redirect permanently on RedirectMatch from $_GET url to semantic url
I am doing some .htaccess settings to improve SEO with semantic URL's. Currently when you go to the semantic URL www.website.com/profile/exampleusername
it works perfectly although i am still able to access the same page without any red alarms rining with the pure get request in the url. www.website.com/profile?username=exampleusername
.
I have tried to user both the redirect and RedirectMatch but i can't get it to work.
Here is the relevant code from the .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]
I want to be able to go to www.website.com/profile?username=exampleusername
and then be redirected to www.website.com/profile/exampleusername
Full .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]
.htaccess
add a comment |
I am doing some .htaccess settings to improve SEO with semantic URL's. Currently when you go to the semantic URL www.website.com/profile/exampleusername
it works perfectly although i am still able to access the same page without any red alarms rining with the pure get request in the url. www.website.com/profile?username=exampleusername
.
I have tried to user both the redirect and RedirectMatch but i can't get it to work.
Here is the relevant code from the .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]
I want to be able to go to www.website.com/profile?username=exampleusername
and then be redirected to www.website.com/profile/exampleusername
Full .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]
.htaccess
add a comment |
I am doing some .htaccess settings to improve SEO with semantic URL's. Currently when you go to the semantic URL www.website.com/profile/exampleusername
it works perfectly although i am still able to access the same page without any red alarms rining with the pure get request in the url. www.website.com/profile?username=exampleusername
.
I have tried to user both the redirect and RedirectMatch but i can't get it to work.
Here is the relevant code from the .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]
I want to be able to go to www.website.com/profile?username=exampleusername
and then be redirected to www.website.com/profile/exampleusername
Full .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]
.htaccess
I am doing some .htaccess settings to improve SEO with semantic URL's. Currently when you go to the semantic URL www.website.com/profile/exampleusername
it works perfectly although i am still able to access the same page without any red alarms rining with the pure get request in the url. www.website.com/profile?username=exampleusername
.
I have tried to user both the redirect and RedirectMatch but i can't get it to work.
Here is the relevant code from the .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]
I want to be able to go to www.website.com/profile?username=exampleusername
and then be redirected to www.website.com/profile/exampleusername
Full .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]
.htaccess
.htaccess
edited Nov 13 '18 at 6:55
asked Nov 12 '18 at 20:53
gamernes konge
163113
163113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use these rules:
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]
I can still access the www.website.com/profile?username=exampleusername which is the part i was asking for. How do you redirect to www.website.com/profile/exampleusername when you go to www.website.com/profile?username=exampleusername
– gamernes konge
Nov 12 '18 at 22:14
This rule is for that redirect. Can you show your full htaccess in question?
– anubhava
Nov 13 '18 at 3:07
I've now added the whole .htaccess
– gamernes konge
Nov 13 '18 at 6:55
ok place my updated rules just belowRewriteEngine On
line and retest
– anubhava
Nov 13 '18 at 7:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269936%2fforce-redirect-permanently-on-redirectmatch-from-get-url-to-semantic-url%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use these rules:
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]
I can still access the www.website.com/profile?username=exampleusername which is the part i was asking for. How do you redirect to www.website.com/profile/exampleusername when you go to www.website.com/profile?username=exampleusername
– gamernes konge
Nov 12 '18 at 22:14
This rule is for that redirect. Can you show your full htaccess in question?
– anubhava
Nov 13 '18 at 3:07
I've now added the whole .htaccess
– gamernes konge
Nov 13 '18 at 6:55
ok place my updated rules just belowRewriteEngine On
line and retest
– anubhava
Nov 13 '18 at 7:33
add a comment |
You can use these rules:
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]
I can still access the www.website.com/profile?username=exampleusername which is the part i was asking for. How do you redirect to www.website.com/profile/exampleusername when you go to www.website.com/profile?username=exampleusername
– gamernes konge
Nov 12 '18 at 22:14
This rule is for that redirect. Can you show your full htaccess in question?
– anubhava
Nov 13 '18 at 3:07
I've now added the whole .htaccess
– gamernes konge
Nov 13 '18 at 6:55
ok place my updated rules just belowRewriteEngine On
line and retest
– anubhava
Nov 13 '18 at 7:33
add a comment |
You can use these rules:
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]
You can use these rules:
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]
edited Nov 13 '18 at 7:32
answered Nov 12 '18 at 21:04
anubhava
520k46316390
520k46316390
I can still access the www.website.com/profile?username=exampleusername which is the part i was asking for. How do you redirect to www.website.com/profile/exampleusername when you go to www.website.com/profile?username=exampleusername
– gamernes konge
Nov 12 '18 at 22:14
This rule is for that redirect. Can you show your full htaccess in question?
– anubhava
Nov 13 '18 at 3:07
I've now added the whole .htaccess
– gamernes konge
Nov 13 '18 at 6:55
ok place my updated rules just belowRewriteEngine On
line and retest
– anubhava
Nov 13 '18 at 7:33
add a comment |
I can still access the www.website.com/profile?username=exampleusername which is the part i was asking for. How do you redirect to www.website.com/profile/exampleusername when you go to www.website.com/profile?username=exampleusername
– gamernes konge
Nov 12 '18 at 22:14
This rule is for that redirect. Can you show your full htaccess in question?
– anubhava
Nov 13 '18 at 3:07
I've now added the whole .htaccess
– gamernes konge
Nov 13 '18 at 6:55
ok place my updated rules just belowRewriteEngine On
line and retest
– anubhava
Nov 13 '18 at 7:33
I can still access the www.website.com/profile?username=exampleusername which is the part i was asking for. How do you redirect to www.website.com/profile/exampleusername when you go to www.website.com/profile?username=exampleusername
– gamernes konge
Nov 12 '18 at 22:14
I can still access the www.website.com/profile?username=exampleusername which is the part i was asking for. How do you redirect to www.website.com/profile/exampleusername when you go to www.website.com/profile?username=exampleusername
– gamernes konge
Nov 12 '18 at 22:14
This rule is for that redirect. Can you show your full htaccess in question?
– anubhava
Nov 13 '18 at 3:07
This rule is for that redirect. Can you show your full htaccess in question?
– anubhava
Nov 13 '18 at 3:07
I've now added the whole .htaccess
– gamernes konge
Nov 13 '18 at 6:55
I've now added the whole .htaccess
– gamernes konge
Nov 13 '18 at 6:55
ok place my updated rules just below
RewriteEngine On
line and retest– anubhava
Nov 13 '18 at 7:33
ok place my updated rules just below
RewriteEngine On
line and retest– anubhava
Nov 13 '18 at 7:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269936%2fforce-redirect-permanently-on-redirectmatch-from-get-url-to-semantic-url%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown