I have very small website where the links are few pages, I want to write few regex so it can match and if match they should redirect to that page, I had already installed urlrewrite in IIS 8
the url i have is:
website.com/page1.cfm
or http://www.website.com/page1.cfm or http://website.com/page1.cfm
to this:
http://website.com/page1
removing the extension
The following regex will match all 3 of your uri formats:
^((http:\/\/|)(www\.|)website\.com\/.+\.cfm)$
To see it in action, and see explanations, go here: https://regexr.com/3ja85
Note: Replace 'website' with your domain.
This regex will match any sub page of your domain (website.com/[anything].cfm)
EDIT:
This regex will return the uri of the 3 formats without the extension while enforcing its presence at the end of a uri:
^((http:\/\/|)(www\.|)website\.com\/.+)(?=\.cfm)
Related
I am using an online tool to crawl my client's website and provide a list of pages / URLs that exist on it.
There is an option to exclude pages, and it gives a regex example of \?.*page=.*$
I would like to ignore everything in the news section (apart from the News page itself)
So would I go with the following?
\?.*news/.*$
If I understand you correctly, you're looking for a regex that matches news/foo or news/foo/bar, but not news/.
You can use this regex for that: .*news/.+
.* string starts with 0 or more character(s)
news/ string includes news/
.+ string ends with 1 or more character(s)
http://regexr.com/3ffj1
I have an old website that has URL's like:
/my-category/my-product
and in my new website, I've managed to keep the 'category' part the same in a lot of case (but not all), but I want to redirect their old products that don't have the .html suffix to the category.
So /my-category/my-product will get redirected to /my-category/ but /my-category/my-product.html will be ignored as it has .html on the end. The new website products have .html on the end, where the old website doesn't.
I also need to stop further rules processing.
The following regular expresion will match any number of \ followed by a string not containing a dot. Then will not match the url will html extension.
^(/[\w-]+)+$
View regex state diagram
I am using the below regex of validating the website URL.
^(http(s?):\/\/)?(www\.)+[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$
It work fine with the below website URL to match:
www.google.com
http://www.google.com/
https://www.google.com/
It also not math below URL
google.com
google.co
www.g#oogle.com
But it will fails to test the below URL:
www...google.com
http://www...google.com/
https://www...google.com/
Please give the suggestion for the same.
I have already go through the below stack overflow URL but answer is not useful for me.
Regular expression for checking website url
What is a good regular expression to match a URL?
To avoid the ... you can use a negative lookahead
For example :
^(?!.*\.\.)(https?:\/\/)?www\.[\w.\-]+(\.[a-zA-Z]{2,3})+(\/[\w.?%#&=\/\-]*)?$
The (?!.*\.\.) in that regex won't allow 2 dots in the string.
I'm developing a Single Page App on the web and just found a exception when redirecting to index.html for all request except request to static files.
This is my current config
modRewrite(['^[^\\.]*$ /index.html [L]'])
This matches everything that does not contain a '.' (period) and redirects the request to index.html.
The problem is if I request a URL like this.
www.example.com/test?q=include.period
It will not redirect this to index.html because it contains a dot in the query string, and it will think this is a static file with the document type .period.
I have tried to get a match on URL not containing a dot before any question mark, but can't get it working.
It is hosted on NodeJS.
I'm not very good with regex so any help would be appriciated.
Examples
Should match
/test
/test/123
/test/123/1
/test/123/1?q=test
/test/123/1?q=test.period
Should mot match (file ending can be any type of file)
/test.js
/img/123.jpg
/script/app.js?version=1.0
Thanks
You could try the below regex,
\/[^.\n]*?(?:=.*)?$
DEMO
All,
I am new to REGEX world...
I know that there are lot of regex avail for validating the common URL with http in it.
But I am looking for a regex to validate the URL in the following formats(without HTTP/HTTPS):
www.example.com/user/login
www.example.com
www.exmaple.co.xx
www.example.com/user?id=234&name=fname
in case if the URL contains only,
www.example(without the domain - .com OR .co.xx)
example.com (without "www")
I should throw an error to the user.
any help would be highly appreciated...
Thanks
Raj
This regex will pass your first set, but not match the second set:
^www\.example\.(com|co.xx)(/.*)?$
In English, this regex requires:
starts with www.example.
followed by either com or co.xx
optionally followed by / then anything
You could be more prescriptive about what can follow the optional slash by replacing (/.*) with (/(user|buy|sell)\?.*) etc