I am trying to create a rule that redirects /parent/special/{anything} to /parent/{anything}. In other words to remove the "special" from the URL if it is there after "parent". This is for a .NET application, more specifically for http://urlrewriter.net. Can someone help with this?
Asked
Active
Viewed 697 times
0
-
2On which language are you developing on? – everton Jan 29 '14 at 00:12
-
...match "/parent/special/" and replace it with "/parent/"? so no regex needed? – mathematical.coffee Jan 29 '14 at 00:12
-
2A rule in what? You may want to provide more information about where you want to use the regex as that will affect the syntax used. – Paige DePol Jan 29 '14 at 00:12
-
I updated the question with more details – TruMan1 Jan 29 '14 at 00:18
-
@TruMan1 updated my answer to include {anything} after /special. – brandonscript Jan 29 '14 at 00:19
-
1Questions asking for code must demonstrate a minimal effort in solving the actual problem, including the attempted code and the encountered issues – HamZa Jan 29 '14 at 00:20
4 Answers
2
If you're using a PCRE compliant language, you could use this:
(\/\w+\/)(?:special\/)?(.*$)
And replace with: $1$2
.
Example: http://regex101.com/r/uM8rA7
If you specifically want /parent
, just replace \w+
with parent
.
Edited to allow for anything after /special
.

brandonscript
- 68,675
- 32
- 163
- 220
0
The following regex:
(\/\w+\/)special\/
Would capture the /parent/
path only if it's followed by special
.

everton
- 7,579
- 2
- 29
- 42
-
-
Oh, didn't notice that on your question. Go with @remus approach then. – everton Jan 29 '14 at 00:20
0
It's actually very simple, try this:
Redirect all requests from: parent/special/(.*)
to: parent/$1
If you're using Apache, the RewriteRule would look like this:
RewriteRule parent/special/(.*) parent/$1 [R=301]

Sean Johnson
- 5,567
- 2
- 17
- 22