0

I'm trying to write a regular expression for a redirect and not having any luck. In this example, an old URL might exist like this:

example.com/about-us/Default.asp

example.com/the-team/Default.asp

Which I want to redirect to:

example.com/about-us/

example.com/the-team/

I've come up with this:

/(\d*)/Default.asp

Which doesn't work...

I've also tried this:

/(\d*)/Default\.asp

As I thought there might be a problem with not having an escape char for the '.', still no luck. Can anyone see what I'm doing wrong?

4

2 回答 2

1

Got it working thanks to what minitech pointed out:

/(.*)/Default.asp$

worked a treat! Thanks

于 2013-07-25T14:59:43.677 回答
1

Since you only need to remove the "Default.asp", you only have to search for that. The regex would look something like this

/Default\.asp/

The dot being escaped since the dot is a special character.

If you're using php, you can do a simple preg_replace

preg_replace('/Default\.asp/', '', 'example.com/about-us/Default.asp');
于 2013-07-25T15:00:28.347 回答