I am using URL Rewriting to make my URLs more understandable(well, thats why it is used mostly).
But I would like to further rewrite them to make them even more understandable.
My home page is at /Pages/1/Home.aspx after rewriting with the below rule.
<rewrite url="~/Pages/(.+)/(.+).aspx" to="~/MainTemplate_$1.aspx?PageName=$2"/>
But I suppose it doesn't look good, at least for home page. So I have applied below rule again.
<rewrite url="~/index.aspx" to="~/Pages/41/Home.aspx"></rewrite>
But that doesn't work. Redirect instead of rewrite works, but the address bar would show clunky details which I don't want.
How do I make it work?
Thanks!
Just had to rearrange the rule order to get it working. Pretty straight forward.
Related
I am writing to ask for your help on how to redirect a URL in nginx.
I would like to remove part of the central URL.
The URL in question is as follows:
Original:
https://example.com/campaigns/jf798l9w3a872/track-url/nm3736ss3md99/d24172761e223c60ae3675f8e7f2a61b1c94ac7d
I wish it would become like this:
https://example.com/campaigns/jf798l9w3a872/nm3736ss3md99/d24172761e223c60ae3675f8e7f2a61b1c94ac7d
I would therefore like to remove only "track-url" in the middle part of the URL.
The parts of the URL between "campaigns" and "track-url" and after are all dynamic and not static.
I have been trying the method suggested by NGINX for days but without success:
rewrite ^/campaigns/(\w+)/track-url/(\w+)$ $1/$2 last;
What am I doing wrong?
Thanks in advance
I've been fixing a strange htaccess issue on my client's WP sites. I found a solution by putting the ReWrite code in the htaccess of each site and then adding a custom permalink code in permalinks and it seems to work EXCEPT for one section.
There are a total of 9 sites with this issue. All of them have a highlights plugin on the front page that's pulling story and images and displaying them on the home page and then a link that goes to the story full page. For my above permalink fix, out of the 9 sites, my fix works on 5 of them but on 4 of them in the highlights section, when you click a link I'm getting a 404.
The strange thing is, with my above fix, the highlight page still publishes, but not with my fix. For example, when you click the "fixed" link it should open as:
mysite.com/central/index.php/highlights/my-page
...but I get a 404. But all I have to do is delete the "index.php" in the above, and the page itself still works:
mysite.com/central/highlights/my-page
So what I now will do is write re-write code and put it in the root htaccess file so that when the page:
mysite.com/central/index.php/highlights/my-page
...is called it will re-write to:
mysite.com/central/highlights/my-page
...and that should fix this pesky issue. Here's the catch - I'm not good at writing code and I used my own hosting company's re-write generator to create a sample for me to see but I can't use it to generate what I need because it only generates for my domain. Since I don't know how to post code to this forum, below is a snap shot of it:
http://designerandpublisher.com/images/rewite-code.jpg
Is there a place where I can just copy and paste the URLs and it will generate the code so it looks like the above snap shot? Or is there some kind of tutorial of what / and \ and dollar signs and the periods and why they're there? I used to set up redirect code a lot simpler than this but it seems more complex now and i'm just hoping there's some kind of generator? Thanks for any assistance.
Adding the following rule should work:
RewriteRule ^central/index.php/(.*) /central/$1 [R=302]
it should turn mysite.com/central/index.php/highlights/my-page to mysite.com/central/highlights/my-page
(Change R=302 to R=301 when you are sure the redirect works)
My project is configured to use the project url a.k.a "localhost/AppName/" and no specific page or anything, everything works fine, but if the user removes the last slash, my hrefs stop working because it ignores the "AppName", so for an example, if I've got an action called Books/Index, if the user removes the last slash "localhost/AppName" and hit enter and then clicks on the link to navigate to the books/index, the full path will be "localhost/Books/Index" which will not work, because it is missing the "AppName" after localhost.
I've tried to change the route and create a rewrite rule but still, no luck.. I'm not sure why this happends and that is what worries me, I've considered changing the way the links are generated, but I think enforcing the "/" would be better, any thoughts on this will be appreciated.
I'm using the default route by the way.
There are some ways trying to fix this, you can google it, quite some solutions there you can try. but none of them perfect.
In my option, the real fix is just to void using the relative path. In your case, you should not use books/index as the href, instead, you should always use the url helper to create the absolute path.
The cause of this problem comes from the asp.net route mechanism, so the root fix is just staying with the route mechanism.
Actually i had this problem too.. i'm not sure if this is the right solution, but this worked fine for me ! Use #Url.Action() for href..
<a href = #Url.Action("ActionName","ControllerName")>
I am using IIS.net's Url Rewrite program on my server to make rules for URL Rewrite. I have pages on my Asp.NET 4.0 Web Site such as Page.aspx, and News.aspx.
When I create a rule for Page.aspx (http://www.foo.com/Page.aspx?PageTitle=Foo to http://www.foo.com/Foo) It works great.
When I create a rule for News.aspx (http://www.foo.com/News.aspx?NewsTitle=Foo to http://www.foo.com/Foo) It works great too.
But when I create rules for both News.aspx and Page.aspx, it fails. Program looks rule order. If News's rule is at top, News.aspx Url rewritten, and Page.aspx Url rewrite fails.
If Page's rule is at top, Page.aspx Url rewritten, and News.aspx Url rewrite fails.
I guess thhis problem occurs because of regex matching. Let me show you:
Rule for News.aspx is at top. So it works fine. But when I click Page.aspx, the RewriteUserFriendlyURL1's Pattern catch my URL, and tries to redirect it News.aspx (Shown in Action Url).
I hope my description is clear.
My question is: How can I avoid this problem? For example I can make a new page called Redirect.aspx, and can redirect all pages to here. I can make 1 rule for Redirect.aspx.
But I think there should be another way to solve this issue with configuring these rules.
Thank you.
The problem is that the regular expressions for RewriteUserFriendlyURL1 and RewriteUserFriendlyURL2 are exactly the same so in that case the order in which they are listed decides which rule gets applied first.
I understand what you are trying to accomplish but it can not work like that. It's impossible for the URL rewrite module to know if /Foo is a news article or a page. Your best option is probably to put the news under /news/<title> and keep /<title> for your regular pages. In that case you can use /news/ to make a difference between news and pages.
So you should keep RedirectUserFriendlyURL2 and RewriteUserFriendlyURL2 the same but change the action URL for RedirectUserFriendlyURL1 to /news/{C:1} and change the pattern for the RewriteUserFriendlyURL1 rule to ^news/([^/]+)/?$ (note: no slash between ^ and news).
<rewrite url="~/forum/viewtopic.php\?t=([0-9]+)" to="~/Handlers/PermRedirect.ashx?ID=$1&action=forumpost" processing="stop"/>
This works great, but how to I make it redirect if t=([0-9]+) exists anywhere in the querystring?
Example URL's that it should match:
/forum/viewtopic.php?t=123&f=rgrg&rt=224
/forum/viewtopic.php?ty=345345&t=123&f=rgrg&rt=224
/forum/viewtopic.php?f=rgrg&rt=224&t=45
Can I make one rule to match them all? One ring, to rule them all.
Does this do the trick in your case?
url="~/forum/viewtopic.php\?.*t=([0-9]+).*