Replacing space from special urls using htaccess
I'm able to replace all %20
with -
from url by using :
.htaccess :
RewriteRule "^(S*)s+(S*)$" /$1-$2 [L,NE,R=302]
RewriteRule "^(S*)s+(S*s+.*)$" $1-$2 [L]
# remove multiple hyphens
RewriteRule ^(.*)-2,(.*)$ /$1-$2 [L,R=302]
Now i want to do this work for only desired urls Not all , url's like like :
Example.com/blog/example%title => example.com/blog/example-title
Example.com/product/example%product => example.com/product/example-product
How i can do this using .htaccess
?
EDIT :
Main Problem is that when i upload images to server with % in name like image 1.jpg
url will redirect me to a name like image-1.jpg
and server can't find image to show
EDIT 2
my .htaccess have this codes beforehand:
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %HTTPS off
RewriteRule .* https://%HTTP_HOST%REQUEST_URI [L,R=301]
.htaccess mod-rewrite
add a comment |
I'm able to replace all %20
with -
from url by using :
.htaccess :
RewriteRule "^(S*)s+(S*)$" /$1-$2 [L,NE,R=302]
RewriteRule "^(S*)s+(S*s+.*)$" $1-$2 [L]
# remove multiple hyphens
RewriteRule ^(.*)-2,(.*)$ /$1-$2 [L,R=302]
Now i want to do this work for only desired urls Not all , url's like like :
Example.com/blog/example%title => example.com/blog/example-title
Example.com/product/example%product => example.com/product/example-product
How i can do this using .htaccess
?
EDIT :
Main Problem is that when i upload images to server with % in name like image 1.jpg
url will redirect me to a name like image-1.jpg
and server can't find image to show
EDIT 2
my .htaccess have this codes beforehand:
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %HTTPS off
RewriteRule .* https://%HTTP_HOST%REQUEST_URI [L,R=301]
.htaccess mod-rewrite
add a comment |
I'm able to replace all %20
with -
from url by using :
.htaccess :
RewriteRule "^(S*)s+(S*)$" /$1-$2 [L,NE,R=302]
RewriteRule "^(S*)s+(S*s+.*)$" $1-$2 [L]
# remove multiple hyphens
RewriteRule ^(.*)-2,(.*)$ /$1-$2 [L,R=302]
Now i want to do this work for only desired urls Not all , url's like like :
Example.com/blog/example%title => example.com/blog/example-title
Example.com/product/example%product => example.com/product/example-product
How i can do this using .htaccess
?
EDIT :
Main Problem is that when i upload images to server with % in name like image 1.jpg
url will redirect me to a name like image-1.jpg
and server can't find image to show
EDIT 2
my .htaccess have this codes beforehand:
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %HTTPS off
RewriteRule .* https://%HTTP_HOST%REQUEST_URI [L,R=301]
.htaccess mod-rewrite
I'm able to replace all %20
with -
from url by using :
.htaccess :
RewriteRule "^(S*)s+(S*)$" /$1-$2 [L,NE,R=302]
RewriteRule "^(S*)s+(S*s+.*)$" $1-$2 [L]
# remove multiple hyphens
RewriteRule ^(.*)-2,(.*)$ /$1-$2 [L,R=302]
Now i want to do this work for only desired urls Not all , url's like like :
Example.com/blog/example%title => example.com/blog/example-title
Example.com/product/example%product => example.com/product/example-product
How i can do this using .htaccess
?
EDIT :
Main Problem is that when i upload images to server with % in name like image 1.jpg
url will redirect me to a name like image-1.jpg
and server can't find image to show
EDIT 2
my .htaccess have this codes beforehand:
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %HTTPS off
RewriteRule .* https://%HTTP_HOST%REQUEST_URI [L,R=301]
.htaccess mod-rewrite
.htaccess mod-rewrite
edited Nov 12 '18 at 18:44
asked Nov 12 '18 at 16:13
SAM NZD
69811228
69811228
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can place known prefixes in your rules:
RewriteRule "^((?:blog|product)/S*)s+(S*)$" /$1-$2 [L,NE,R=302,NC]
RewriteRule "^((?:blog|product)S*)s+(S*s+.*)$" $1-$2 [L,NC]
# remove multiple hyphens
RewriteRule ^((?:blog|product)/.*)-2,(.*)$ /$1-$2 [L,R=302,NE,NC]
Not worked ! i tested for this url :site.com/blog/one/64/how%to%relax
. i want to be/blog/one/64/how-to-relax
.
– SAM NZD
Nov 12 '18 at 18:30
Space character is%20
not%
. I have tested withhttp://localhost/blog/one/64/how%20to%20relax
that got correctly redirected tohttp://localhost/blog/one/64/how-to-relax
– anubhava
Nov 12 '18 at 18:38
1
Finally i moved your codes top of everything i had beforehand in.htaccess
and it worked ! i did not know reason
– SAM NZD
Nov 12 '18 at 19:03
1
Yes indeed all redirect rules should be placed before internal rewrite rules becauseRewriteRule ^(.*)$ index.php/$1 [L]
changes all URIs toindex.php/...
– anubhava
Nov 12 '18 at 19:12
1
thanks you are wizard
– SAM NZD
Nov 12 '18 at 19:54
|
show 3 more comments
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%2f53266065%2freplacing-space-from-special-urls-using-htaccess%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 place known prefixes in your rules:
RewriteRule "^((?:blog|product)/S*)s+(S*)$" /$1-$2 [L,NE,R=302,NC]
RewriteRule "^((?:blog|product)S*)s+(S*s+.*)$" $1-$2 [L,NC]
# remove multiple hyphens
RewriteRule ^((?:blog|product)/.*)-2,(.*)$ /$1-$2 [L,R=302,NE,NC]
Not worked ! i tested for this url :site.com/blog/one/64/how%to%relax
. i want to be/blog/one/64/how-to-relax
.
– SAM NZD
Nov 12 '18 at 18:30
Space character is%20
not%
. I have tested withhttp://localhost/blog/one/64/how%20to%20relax
that got correctly redirected tohttp://localhost/blog/one/64/how-to-relax
– anubhava
Nov 12 '18 at 18:38
1
Finally i moved your codes top of everything i had beforehand in.htaccess
and it worked ! i did not know reason
– SAM NZD
Nov 12 '18 at 19:03
1
Yes indeed all redirect rules should be placed before internal rewrite rules becauseRewriteRule ^(.*)$ index.php/$1 [L]
changes all URIs toindex.php/...
– anubhava
Nov 12 '18 at 19:12
1
thanks you are wizard
– SAM NZD
Nov 12 '18 at 19:54
|
show 3 more comments
You can place known prefixes in your rules:
RewriteRule "^((?:blog|product)/S*)s+(S*)$" /$1-$2 [L,NE,R=302,NC]
RewriteRule "^((?:blog|product)S*)s+(S*s+.*)$" $1-$2 [L,NC]
# remove multiple hyphens
RewriteRule ^((?:blog|product)/.*)-2,(.*)$ /$1-$2 [L,R=302,NE,NC]
Not worked ! i tested for this url :site.com/blog/one/64/how%to%relax
. i want to be/blog/one/64/how-to-relax
.
– SAM NZD
Nov 12 '18 at 18:30
Space character is%20
not%
. I have tested withhttp://localhost/blog/one/64/how%20to%20relax
that got correctly redirected tohttp://localhost/blog/one/64/how-to-relax
– anubhava
Nov 12 '18 at 18:38
1
Finally i moved your codes top of everything i had beforehand in.htaccess
and it worked ! i did not know reason
– SAM NZD
Nov 12 '18 at 19:03
1
Yes indeed all redirect rules should be placed before internal rewrite rules becauseRewriteRule ^(.*)$ index.php/$1 [L]
changes all URIs toindex.php/...
– anubhava
Nov 12 '18 at 19:12
1
thanks you are wizard
– SAM NZD
Nov 12 '18 at 19:54
|
show 3 more comments
You can place known prefixes in your rules:
RewriteRule "^((?:blog|product)/S*)s+(S*)$" /$1-$2 [L,NE,R=302,NC]
RewriteRule "^((?:blog|product)S*)s+(S*s+.*)$" $1-$2 [L,NC]
# remove multiple hyphens
RewriteRule ^((?:blog|product)/.*)-2,(.*)$ /$1-$2 [L,R=302,NE,NC]
You can place known prefixes in your rules:
RewriteRule "^((?:blog|product)/S*)s+(S*)$" /$1-$2 [L,NE,R=302,NC]
RewriteRule "^((?:blog|product)S*)s+(S*s+.*)$" $1-$2 [L,NC]
# remove multiple hyphens
RewriteRule ^((?:blog|product)/.*)-2,(.*)$ /$1-$2 [L,R=302,NE,NC]
answered Nov 12 '18 at 16:49
anubhava
520k46316390
520k46316390
Not worked ! i tested for this url :site.com/blog/one/64/how%to%relax
. i want to be/blog/one/64/how-to-relax
.
– SAM NZD
Nov 12 '18 at 18:30
Space character is%20
not%
. I have tested withhttp://localhost/blog/one/64/how%20to%20relax
that got correctly redirected tohttp://localhost/blog/one/64/how-to-relax
– anubhava
Nov 12 '18 at 18:38
1
Finally i moved your codes top of everything i had beforehand in.htaccess
and it worked ! i did not know reason
– SAM NZD
Nov 12 '18 at 19:03
1
Yes indeed all redirect rules should be placed before internal rewrite rules becauseRewriteRule ^(.*)$ index.php/$1 [L]
changes all URIs toindex.php/...
– anubhava
Nov 12 '18 at 19:12
1
thanks you are wizard
– SAM NZD
Nov 12 '18 at 19:54
|
show 3 more comments
Not worked ! i tested for this url :site.com/blog/one/64/how%to%relax
. i want to be/blog/one/64/how-to-relax
.
– SAM NZD
Nov 12 '18 at 18:30
Space character is%20
not%
. I have tested withhttp://localhost/blog/one/64/how%20to%20relax
that got correctly redirected tohttp://localhost/blog/one/64/how-to-relax
– anubhava
Nov 12 '18 at 18:38
1
Finally i moved your codes top of everything i had beforehand in.htaccess
and it worked ! i did not know reason
– SAM NZD
Nov 12 '18 at 19:03
1
Yes indeed all redirect rules should be placed before internal rewrite rules becauseRewriteRule ^(.*)$ index.php/$1 [L]
changes all URIs toindex.php/...
– anubhava
Nov 12 '18 at 19:12
1
thanks you are wizard
– SAM NZD
Nov 12 '18 at 19:54
Not worked ! i tested for this url :
site.com/blog/one/64/how%to%relax
. i want to be /blog/one/64/how-to-relax
.– SAM NZD
Nov 12 '18 at 18:30
Not worked ! i tested for this url :
site.com/blog/one/64/how%to%relax
. i want to be /blog/one/64/how-to-relax
.– SAM NZD
Nov 12 '18 at 18:30
Space character is
%20
not %
. I have tested with http://localhost/blog/one/64/how%20to%20relax
that got correctly redirected to http://localhost/blog/one/64/how-to-relax
– anubhava
Nov 12 '18 at 18:38
Space character is
%20
not %
. I have tested with http://localhost/blog/one/64/how%20to%20relax
that got correctly redirected to http://localhost/blog/one/64/how-to-relax
– anubhava
Nov 12 '18 at 18:38
1
1
Finally i moved your codes top of everything i had beforehand in
.htaccess
and it worked ! i did not know reason– SAM NZD
Nov 12 '18 at 19:03
Finally i moved your codes top of everything i had beforehand in
.htaccess
and it worked ! i did not know reason– SAM NZD
Nov 12 '18 at 19:03
1
1
Yes indeed all redirect rules should be placed before internal rewrite rules because
RewriteRule ^(.*)$ index.php/$1 [L]
changes all URIs to index.php/...
– anubhava
Nov 12 '18 at 19:12
Yes indeed all redirect rules should be placed before internal rewrite rules because
RewriteRule ^(.*)$ index.php/$1 [L]
changes all URIs to index.php/...
– anubhava
Nov 12 '18 at 19:12
1
1
thanks you are wizard
– SAM NZD
Nov 12 '18 at 19:54
thanks you are wizard
– SAM NZD
Nov 12 '18 at 19:54
|
show 3 more comments
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%2f53266065%2freplacing-space-from-special-urls-using-htaccess%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