哪个更好(对于用户,对于长寿,对于性能,对于任何事情)具有:
http:// {site}/{login}例如http://wildobs.com/adam_jack
要么
HTTP:// {网站} /用户/ {登录}
前者的优点:
前者的缺点:
显然,这对于正确(或错误并坚持)很重要,因为所有用户定义的URL都基于它.改变它似乎是网站自杀.
缺点(特别是随着时间的推移)是否超过职业选手?
对于SEO,.html扩展名比.php和.aspx更好吗?或者扩展名为url比所有人更好
我有一个应用程序,大多数情况下都使用不太友好的动态URL。我为某些内容提供了友好的URL,但是这些URL仅用作应用程序的入口,在此之后,所有生成的URL都是不友好的。
我的问题是,如果我知道用户在可以为其生成友好URL的页面上,并且他们选择将其添加为书签,是否有办法告诉浏览器为该友好的URL加上书签,而不是地址栏中的内容? ?
我知道如何进行URL的重写,例如:
www.example.com/index.php?id=1&cat=3to www.example.com/1/3/(或者其他).我知道.
我不知道的是如何在所有页面中更改我的整个链接以链接到漂亮的URL.我所有网站的链接都是旧时尚(<a href="index.php?id=1&cat=2">),还有很多.
如果用户点击index.php?id = 1,我问是否有人有想法或知道如何自动重定向到那个漂亮的URL.(如果你在网址中更改标题,几乎就像这个网站Stackoverflow).
所以我的预算是......
使用.htaccess读取index.php?id = 1&cat = 2来重写索引/ 1/3本身再次解释(奇怪)
一个php文件,用于重定向htaccess重写为原始的...
结论:<a href="index.php?id=1&.....">自动更改为index/1/2
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
##################################
# This turns index.php?id=1&cat=2 into index/1/2 and then back 'transparent' into index.php?id=1&cat=2 if you have old fashioned
# links in your site and don't want to change them :)
# Avoid mod_rewrite infinite loops
# This is critical if you want to use this code
RewriteCond %{ENV:REDIRECT_STATUS} …Run Code Online (Sandbox Code Playgroud) 我在这里发表评论:http://bakery.cakephp.org/articles/PHPdiddy/2006/10/06/custom-urls-from-the-site-root
那说:
只需改变最后一行.
Router :: connect('/ ',array('controller'=>'members','action'=>'show'));
to
Router :: connect('(?!admin | items | images)(.*)',array('controller'=>'members','action'=>'show'));
有些人能够让它工作......但是我看起来并不合适,所以我尝试了以下方法,但仍然没有运气:
Router::connect('(?!/admin|/items|/images)(/.*)',
array('controller' => 'members','action' => 'show'));
Run Code Online (Sandbox Code Playgroud)
无论如何,目标是拥有一个像http:// domainname/username这样的URL ,映射到用户唯一的id.它适用于/*,但我宁愿不使用该方法.想法?
更新到解决方案: 我使用下面的选定答案并添加以下内容.它可能对其他人有帮助.
$misc = array(*your misc webroot, admin route items here...*);
$notList = array_merge(Configure::listObjects('plugin'),Configure::listObjects('controller'));
$notListLowerCase = array();
foreach ($notList as $key=>$item):
$notListLowerCase[] = strtolower(preg_replace("/(.)([A-Z])/","\\1_\\2",$item));
endforeach;
$notList = array_merge($notList,$misc,$notListLowerCase);
$notList = implode('|', $notList);
Router::connect('/:username',
array(
'controller'=>'users',
'action'=>'view'
),
array(
'username' => '\b(?:(?!'.$notList.')\w)+\b'
)
);
Run Code Online (Sandbox Code Playgroud) 在尝试了解如何创建更好的URL以方便用户而不牺牲SEO时,我正在研究不同网站的结构.我有一些与以下相关的问题:
亚马逊 - >/typical-product-slug/dp/{id}
stackoverflow - >/questions/{id}/question-slug
yardsellr - > for_sale#!/ product-slug - {id}
[1]为什么亚马逊将域名放在域名后面就像stackoverflow那样使它更容易理解并提供目录结构?此外,将{id}保持在最后会使其更容易出现剪切错误.
[2]亚马逊和stackoverflow对{id}的定位是否与亚马逊的{id}是字母数字和stackoverflow的数字有关?也许字母数字对于用户来说更加神秘,因此亚马逊将其置于最正确的位置,从SEO的角度来看?
[3]对于亚马逊来说,没有使用关键词'产品',甚至像'书籍'或'音乐'这样的高级别类别代替'dp'会使SEO更有效?
[4] yardsellr for it的尾随{id}不使用'/'而是' - '作为标记.Google表示URL dir结构的深度并不重要.什么是受益于这种结构的码头,它只是因为slu and和id既独特又相同?这与深度有关吗?如果他们已将id放在slug之前,这是否会影响SEO?
我知道大多数这些都没有直接的答案.寻找你的经验和想法,以便我可以学习.
谢谢.
参考:Microsoft.AspNet.FriendlyUrls
我正在使用表单身份验证和FriendlyUrls.我有一个名为"Account"的子目录,其中包含文件"Register.aspx".我需要授予文件"Register.aspx"的权限,并通过web.config拒绝所有其他文件的权限.我尝试了各种设置,但Register.aspx文件未获得许可.
web.config中
<system.web>
<authentication mode="Forms">
<forms loginUrl="Account/login" name="LOGIN" defaultUrl="Account/Logged" timeout="15" cookieless="UseDeviceProfile" protection="All" slidingExpiration="true" />
</authentication>
</system.web>
<location path="Account">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="Account/Register">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
Run Code Online (Sandbox Code Playgroud) 我正在创建一个Struts2 Web应用程序.
我想要一个URL www.xyz.com/portal/orgCode/signin,这个orgCode是动态的,所以我正在使用正则表达式.
我配置struts.xml如:
<constant name="struts.devMode" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.action.extension" value=",html,action" />
<constant name="struts.action.excludePattern" value=".*unfiltered.*,.*\\.nofilter" />
<constant name="struts.multipart.maxSize" value="2097152000"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />
<package name="portal" namespace="/portal/{orgCode}" extends="default">
<interceptors>
<interceptor name="portalUrlInterceptor"
class="com.wtmit.service.portal.interceptor.PortalCommonInterceptor">
</interceptor>
<interceptor-stack name="commonPortalUrlInterceptor">
<interceptor-ref name="portalUrlInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<action name="signin" method="signin"
class="com.wtmit.service.portal.action.PortalSignInAction">
<interceptor-ref name="commonPortalUrlInterceptor"></interceptor-ref>
<result name="portalSignIn" type="tiles">portalSignIn</result>
<result name="successLogin" type="redirect">home</result>
</action>
</package>
Run Code Online (Sandbox Code Playgroud)
这工作正常,但像www.xyz.com/mainLogin以下网址不适用于以下配置:
<package name="main" namespace="/" extends="default">
<action name="*Login" method="{0}" class="com.service.user.action.LoginAction">
<result …Run Code Online (Sandbox Code Playgroud) 如果没有为ASP.Net Web窗体项目打开FriendlyUrls,以下代码可以正常工作:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: '/Default.aspx/GetData',
type: 'POST',
beforeSend: function( xhr ) {
xhr.setRequestHeader("Content-type",
"application/json; charset=utf-8");
},
success: function (result) {
var resultData = (result.d? result.d : result);
alert(resultData);
},
error : function(){
alert('error');
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
这是页面方法的服务器端代码(WebMethod):
[System.Web.Services.WebMethod]
public static string GetData()
{
return "Hello";
}
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中加载页面时,我可以看到响应为{ "d" : "Hello" },这是预期的结果.
现在,如果使用NuGet包Microsoft.AspNet.FriendlyUrls添加友好URL ,则相同的代码将不起作用.当FriendlyUrls打开时,我将jquery ajax调用中的url更改为"/ Default/GetData",但后来我不会收到预期的结果.而是我收到Default.aspx页面的html.
我正在努力找出为什么这不起作用,我唯一改变的是为FriendlyUrls添加nuget包!
我一直试图找到解决方案,我能找到的最接近可读答案是:
使用jQuery for AJAX和ASP.NET Webforms
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
请注意,给定答案中的所有相关帖子都不使用FriendlyUrls.我也看到了一些答案,表明jquery ajax调用可以与MVC,WebAPI一起使用,但我的项目仅限于使用ASP.Net Web Forms.
我做错了什么或错过了什么吗?有没有人遇到过他们项目的相同场景?如果是这样,你能否回答一下如何解决这个问题?非常感谢您花时间阅读和回复.
在我的Global.asax中我有这些规则
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.EnableFriendlyUrls();
RouteTable.Routes.MapPageRoute("", "Home", "~/Default.aspx");
RouteTable.Routes.MapPageRoute("", "Carrello", "~/Carrello.aspx");
RouteTable.Routes.MapPageRoute("", "Checkout", "~/Checkout2.aspx");
RouteTable.Routes.MapPageRoute("", "Ricerca-Prodotto/{Filtri}/{Pagina}", "~/ProductsSearch.aspx");
RouteTable.Routes.MapPageRoute("", "Prodotto/{ProductId}", "~/Product.aspx");
RouteTable.Routes.MapPageRoute("", "Prodotti/{Menu}/{Marca}/{Categoria}/{Pagina}", "~/Product.aspx");
}
Run Code Online (Sandbox Code Playgroud)
我还有UrlRewrite来管理
protected void Application_BeginRequest(object sender, EventArgs e)
{
System.Collections.Generic.List<Rewrite> rewrites = Rewrite.getRules();
String fullOriginalPath = Request.Url.ToString();
int index = 0;
if(fullOriginalPath.Contains("www."))
index = fullOriginalPath.IndexOf('/', fullOriginalPath.IndexOf("e-miko.com")) + 1;
else
index = fullOriginalPath.IndexOf('/', fullOriginalPath.IndexOf("localhost")) + 1;
string chiave = fullOriginalPath.Substring(index);
Utility.WriteToLog(chiave);
foreach (Rewrite r in rewrites)
{
if(r.Chiave == chiave)
{
string url = …Run Code Online (Sandbox Code Playgroud)