SEO friendly url gives a "A potentially dangerous Request.Path" on IIS - iis

I'm creating a SEO friendly URL which has some product names, which might have not-so-url friendly characters, eg:
www.foo.com/some-friend/product-name-bla-%numbers-maybe/1234567
I'm only interested in the last id number, however currently IIS redirects to a fault page on some of of my URLs.
I do not wish to disable the Request.Path check.
My question is - How do I sanitize the URLs so they will not bother IIS (preferably in C#) ?

ASP.NET has HttpUtility which lets you escape illegal characters in url or html string.
HttpUtility.UrlEncode(yourString);
Even though you are only going to need the ID at the end of the URL to get data from database, it is a good idea to also check if the SEO friendly part of the url is identical to original url.
If for whatever reason it has changed you should do a 301 permanent redirect to the original in order to avoid creating duplicate content.
Also setting up a canonical meta tag would help you prevent that issue.

Related

redirect numerous dynamic urls to home page via .htaccess

I am trying to clean up a previously hacked WordPress site, and domain name reputation, the site has new hosting and is now on a different CMS system, but there are hundreds of spam links in Google I need to get rid of, they look like example.com/votes.php?10054nzwzm75042pw205039
Domain name, then votes.php?**** etc.. Numbers letters all sorts.
So how do I redirect ANYTHING that starts with the domain name then /votes.php?***
Any help greatly appreciated
Unless you have multiple domains, you don't need to explicitly check the domain name.
To send a "410 Gone" for anything that contains /votes.php in the URL-path (and any query string), you can do something like the following at the top of your root .htaccess file using mod_rewrite:
RewriteEngine On
# Serve a 410 Gone for any requests to "/votes.php"
RewriteRule ^votes\.php$ - [G]
A 410 is preferable to a "redirect" if you want to get these URLs removed from the search engines as quickly as possible.
To expedite the process of URL removal from Google then use Google's Removal Tool as well.
If you redirect these pages to the homepage then it will likely be seen as a soft-404 by Google and these URLs are likely to remain in the search results for a lot longer.

Liferay Top Level Friendly URL

Is there a way to create / process friendly URLs in liferay like this?
http://myserver.com/JonDoe
... where John Doe is the name of a clients whose data should be displayed.
A little more detail:
I am not talking about getting rid of the "web" or "group" for friendly urls, I am taking about having a friendly url right after the first "/".
We want to create URLs in the form of http://server/ClientName where ClientName resolves to the name of a Client. This is an issue since normally liferay would expect a friendly URL after the first "/". So we ned to intercept that somehow.
The process should be like this (pseudo code):
1) inspect values after first "/"
2) If value after "/" is the name of a client, send user to client display page and display client information
3) If there is no client with the given name, interpret it as friendly url and do normal liferay behaviour.
Is there a way to do this in liferay ?
Sounds like you want to get rid of the /web/ or /group/ parts of the URLs? This is possible with proper configuration of the virtual host - you'll map the site to the domain name, then you have total freedom to name the pages, even hierarchically (e.g. /JonDoe/home)
So far this was simple configuration. If you want /JonDoe to point to another site than /JoeShmoe (e.g. just get rid of /web/ or /group/), you'll have to dig deeper and write quite some customization plugins that change the name resolving (and generation of URLs)
If you want to have one URL for a page, you can just set the friendly URL for that page (see Olafs remark about virtual hosts as well)
If you want to have a limited set of URLs for one page, you can create a page of type Link to Page for each URL and select the original page. To identify the current URL when rendering you portlet you can use PortalUtil.getCurrentURL(renderRequest)
If you want to have many URLs for one page you could use a FriendlyUrlMapper, which allows URLs like http://myserver.com/page/-/myPortlet/JonDoe.
If you want to have many "root" URLs (i mean without the /page/-/myPortlet part), you will have to create an Liferay EXT plugin, extend com.liferay.portal.util.PortalImpl and overwrite getPortletFriendlyURLMapperLayoutQueryStringComposite. I've done the same by implementing a strategy that checks if a page exists for a specific given URL and otherwise uses the URL as parameter for a FriendlyURLMapper.

301 redirect all ugly permalinks from old site to new site

So I overhauled a complete website the other day and found some of the old pages snippets in the google search results. The old page had an ugly link structure such as domain.com/index.php?article_id=123. The new site uses pretty permalinks such as domain.com/pagetitle.
Is there a piece of code I could put into the .htaccess file in order to redirect all ugly permalinks to the new site?
Edit
Additional info: The old links don't exist anymore. The old site and the new one's structure differs a lot, not all contents from the all site were adapted. Main problem is that I don't want the old links in the google search results to always throw a 404 at the user.
Maybe something of a
RedirectMatch ^/index.php?$ http://www.example.com/somepage
This will redirect all pages starting from index.php to another location
I don't have the rep to comment on the other answer, but that is a very improper solution if you value your SEO at all. A redirect is your way of telling Google "I've got the same page, I just moved it". There's a much better way to do this that won't negatively affect your SEO at all.
You should create some logic to redirect those old links to your new links.
Here's an example of how you could do it:
Go to the beginning of your program, before any logic takes place.
Use code to retrieve the requested page. In this case, you might be able to get away with simply checking for GET variables that match article_id.
If the requested page is a match for your GET variable, run a query to see if the article exists. (Obviously, you'll still want to 404 articles that don't exist).
Retrieve the content used to generate the new, more SEO-friendly URL's. This is probably the article title or something.
Write some code to generate the new article title. At this point, if this is working properly, you should be able to system print that new URL to make sure it's correct.
301 redirect to the new URL. Don't 302 or any other number, 301 redirect it. This lets search engines know it's the same page and content, but it has permanently moved.

.htaccess URL rewrite not working for Ecwid product link

I used the third party cart system from Ecwid. When I click on any prouduct, it shows this link or URL:
http://www.bestsports.ca/product.php#!/~/product/category=9414048&id=11484861
How can I rewrite this URL instead of showing category id? I want to show the product name. I already tried your above instruction but its not working. Can you please explain is it possible to make this URL into this SEO friendly URL?
http://www.bestsports.ca/MMAGEAR/productname/
I want so show first URL like above URL.
It is not possible for .htaccess to rewrite URLs with a hash (#) symbol in them. That is because everything after the hash is considered a fragment identifier. The purpose of the fragment identifier is to specify the content to be show within the HTML document. It may be handled:
By the browser by scrolling to the correct place in the page
By JavaScript by loading and displaying the specified content
In your case, it appears to specify the AJAX content to be displayed. That is handled client side by JavaScript.
The hash and everything after it are not even sent to your server. They are client side only. Because of this, there is no possibility for your server to rewrite a URL based on the information after the hash. .htaccess can't even get this information.
The only way for you to rewrite these URLs would be to modify the JavaScript in the page to have it change the document.location to the URL of your choice.

Dynamically creating URLs for other websites

I'd like to know how websites have created URLs with other domains like these on trafficestimate.com.
I'm guessing it's some .htaccess stuff to redirect domain names to a dynamic page?
Thanks
Your URL has an GET Request. So when someone calls the page http://google.com/search with the parameters hl=en, safe=off etc., the page can process those parameters. So for instance safe=off means that you want to get back any search result. The q=site:... is your search string. In this case Google will look it up in its database and give you the results. So when you call this URL there is probably no .htaccess processing done. However you can process the URL and GET request with .htacces and i.e. redirect the user to another page.
Maybe you'll describe a bit further what exactly you trying to do/want to know. This makes explaining easier.
EDIT: After reading Gumbo's comment I looked at the Google result page. So maybe your question means the trafficestimate-URLs. They look like http://trafficestimate.com/example.org. This is really a good case for .htaccess. So using .htaccess they take the URL and redirect it to http://www.trafficestimate.com/websites/?domain=example.org. Here you have again a GET request and an application builds the page.
Some URL rewriting is probably involved. Otherwise they would have to create an existing file for every possible request.
Using Apache’s mod_rewrite in a .htaccess file is one option. But since the server identifies itself with “Microsoft-IIS/7.5”, they are probably rather using ISAPI_Rewrite, a mod_rewrite derivative for Microsoft’s IIS.

Resources