kentico
संस्कृति-विशिष्ट URL
खोज…
संस्कृति-विशिष्ट URL कॉन्फ़िगर करना
SEO के लिहाज से कल्चर-विशिष्ट URL होना फायदेमंद हो सकता है।
निम्न पृष्ठ का अंग्रेजी संस्करण:
http://www.mydomain.com/insurance
में अनुवाद करेंगे:
http://www.mydomain.nl/verzekering
के बजाय:
http://www.mydomain.nl/nl-nl/insurance
इसे प्राप्त करने के अधिक दृष्टिकोण हैं:
आमतौर पर, आप चाहते हैं कि URL दस्तावेज़ों के नामों से प्राप्त हों। ऐसा करने के लिए, सुनिश्चित करें कि आपने URL पथ का उपयोग सही करने के लिए नाम पथ सेट किया है। डिफ़ॉल्ट रूप से, यह गलत है।
यदि डिफ़ॉल्ट URL निर्माण पैटर्न आपके लिए काम नहीं करता है, तो आप आधिकारिक प्रलेखन में वर्णित URL को मैन्युअल रूप से सेट कर सकते हैं। हालाँकि, यह विकल्प केवल तभी व्यवहार्य है जब आपको छोटी मात्रा के URL को समायोजित करने की आवश्यकता हो।
यदि आप एक कस्टम पैटर्न के आधार पर यूआरएल के निर्माण को स्वचालित करना चाहते हैं तो आप एक कस्टम मॉड्यूल लागू कर सकते हैं।
using System;
using System.Text;
using CMS;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.Helpers;
[assembly: RegisterModule(typeof(CultureSpecificUrlsModule))]
public class CultureSpecificUrlsModule : Module
{
public CultureSpecificUrlsModule() : base("CultureSpecificUrlsModule")
{
}
protected override void OnInit()
{
base.OnInit();
/***
* Before the node gets saved, we'll update it's DocumentUrlPath.
* The system will ensure it'll be saved in a valid URL format.
*/
DocumentEvents.Update.Before += Update_Before;
}
private void Update_Before(object sender, DocumentEventArgs e)
{
/***
* Here you can apply conditions before you actually update the DocumentUrlPath.
* E.g. you can check for the document's culture.
*/
UpdateUrlPath(e.Node);
}
public static void UpdateUrlPath(TreeNode node)
{
/***
* You can set the DocumentUrlPath to whatever you want.
* In this example we're using a method extracted from CMS.DocumentEngine.TreePathUtils.
* The same method is used to generate a URL for the default culture.
*/
node.DocumentUrlPath = GetUrlPathFromNamePathInternal(node.DocumentNamePath);
}
internal static string GetUrlPathFromNamePathInternal(string namePath, int level = -1)
{
// Check valid path
if (String.IsNullOrEmpty(namePath) || (namePath == "/"))
{
return null;
}
// For top level the path is always /
if (level == 0)
{
return "/";
}
// Ensure maximal level if not set
if (level < 0)
{
level = Int32.MaxValue;
}
// Get the path parts
string[] pathParts = namePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
int currentLevel = 1;
var path = new StringBuilder();
foreach (string part in pathParts)
{
string shortPart = part;
// Shorten the part to the allowed maximum
if (shortPart.Length > TreePathUtils.MaxAliasLength)
{
shortPart = shortPart.Substring(0, TreePathUtils.MaxAliasLength);
}
path.Append("/", shortPart);
if (++currentLevel > level)
{
break;
}
}
return path.ToString();
}
}
- यदि आपको मौजूदा पृष्ठों को अपडेट करने की आवश्यकता है (जैसे यदि आप अपनी परियोजना को विकसित करने से पहले URL पथ के लिए नाम पथ का उपयोग करना भूल गए हैं) तो आप एक सरल कंसोल एप्लिकेशन का उपयोग कर सकते हैं जो आपके लिए URL अपडेट करेगा:
using System;
using CMS.DataEngine;
using CMS.DocumentEngine;
namespace CultureUrlsUtil
{
class Program
{
static void Main(string[] args)
{
CMSApplication.Init();
/*** Here you can narrow down the scope of documents that should be updated using DocumentQuery ***/
var pages = DocumentHelper.GetDocuments().Culture("es-es");
foreach (var page in pages)
{
/*** Here we are calling code from the example above. ***/
CultureSpecificUrlsModule.UpdateUrlPath(page);
page.Update();
}
Console.Write("URLs created!");
Console.ReadLine();
}
}
}
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow