How do i hide my page extension for example
mysite.com/index.asp
how do i take off the extension .asp
and also how i hide tables field names in a URL. example is I'm displaying details of a record of 2 . so the link is going to be
mysite.com/details?record_id=2
how do i take off the record_1d=2 to make it
mysite.com/details
I'm working with asp classic.
thanks
You want this:
http://www.iis.net/downloads/microsoft/url-rewrite
Your rule would look like this:
<rewrite>
<rules>
<rule name="RewriteASP">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.asp" />
</rule>
</rules>
</rewrite>
As far as I'm aware you can't rewrite the querystrings without retooling your code to pass data via HTTP posts.
Related
I have the below config for url rewrite in my IIS
<rewrite>
<rules>
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>
The negate directive is there to prevent rewrite for website assets files (css, fonts, etc.) as well as other files from the documents upload/download section.
The issue I just came across is this, one of the urls is like this http://intranet/HR/Training-Basics however when I try to navigate to this url I get 404 because it is being caught by the negate function for file extension ics.
So, I need to be able to access this url, but at the same time I need to be able to download the "ics" files. What is the best way to do it?
You could modify the condition pattern from ics to\.ics, so that the rewrite rule will only rewrite based on file extension instead of specific string segment.
<rule name="Rewrite CI Index">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="\.(css|js|jpg|jpeg|png|gif|ico|htm|html|csv|ttf|woff|woff2|pdf|mp4|mov|ics)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(php_scripts)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/documents/intranet_documents/" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
I have several pages on my site that have long and unreadable URLs that I'd like to be able shorten. The problem I'm having is appending query strings with variable values.
For example:
"www.example.com/dir1/dir2/filename.php" shortens to "www.example.com/file".
"www.example.com/dir1/dir2/filename.php?id=2" would be "www.example.com/file/2".
"www.example.com/dir1/dir2/filename.php?id=2&alt=6" would be "www.example.com/file/2/6".
The values of 'id' and 'alt' are then used by our page to access information in our database, which determines the contents of the page. These values can change, and there is no set amount.
Right now I've got the first example working fine using the following rewrite rules:
<rewrite>
<outboundRules>
<remove name="OutboundRewriteUserFriendlyURL1" />
</outboundRules>
<rewriteMaps>
<rewriteMap name="StaticRewrites">
<add key="/file" value="/dir1/dir2/filename.php" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
</rules>
</rewrite>
But I haven't been able to find anything that would allow the URLs to contain variables. Everything I've seen has used static rewrites like my current solution is using, and I can't find anything about allowing arbitrary parameters.
EDIT:
Found a better solution that doesn't use a Rewrite Map. I had attempted a simliar rule previously, but due to the IIS setup on our testing environment it wasn't working as expected. This version should work for most people.
<rule name="Curricula View" stopProcessing="true">
<match url="/file(?:/(\d+)(?:/(\d+))?)?" />
<action type="Rewrite" url="/dir1/dir2/filename.php?id={R:1}&alt={R:2}" appendQueryString="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
</rule>
Using this rule I was able to avoid using a rewrite map altogether. I had attempted to use something like this originally, but due to the setup of our test environment it wouldn't work without some weird tweaks. This version should work in all normal environments.
<rule name="Curricula View" stopProcessing="true">
<match url="/file(?:/(\d+)(?:/(\d+))?)?" />
<action type="Rewrite" url="/dir1/dir2/filename.php?id={R:1}&alt={R:2}" appendQueryString="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
</rule>
EDIT:
I was also able to get the original version with a rewrite map working for anyone interested.
<rule name="Rewrite Map with Variables" enabled="true">
<match url="^(.+?)/?/(.*)$" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{ProductMap:{R:1}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="/dir1/dir2/filename.php?id={C:0}&other={R:2}" appendQueryString="true" />
</rule>
i've created friendly URLs for a website using the web.config file in IIS 7.5.
i've created a rule for an articles page which looks like this :
<rule name="RedirectUserFriendlyURL10" stopProcessing="true">
<match url="^articles\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^title=([^=&]+)&id=([^=&]+)$" />
</conditions>
<action type="Redirect" url="articles/{C:1}/{C:2}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL10" stopProcessing="true">
<match url="^articles/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="articles.php?title={R:1}&id={R:2}" />
</rule>
this works fine.
an example of the friendly URL would look like this : http://www.example.com/articles/name_of_article/2104
now my client wants to add a 'landing page' which will list all of the articles, rather than going directly to an individual article.
they want the link to read http://www.example.com/articles or something very similar.
now i've changed the code on the page articles.php so that if there is no id passed in the querystring, or if the querystring id is 0 then the page will display the article list as required... if there is an id it will show only that specific article.
my question is, how can i write a rule so that it will rewrite the URL correctly
e.g.
http://www.example.com/articles.php?id=2104&title=name_of_article
becomes
http://www.example.com/articles/name_of_article/2104
and
http://www.example.com/articles.php?id=0
becomes
http://www.example.com/articles
only the first part currently works using the rule shown above.
We are trying to use Imageresizer with the disk cache feature as well as the sqldatareader. It expects urls to be in the form of:
http://somesite.com/image/{imageid}.{extension}
whereas all the image links in our site is currently:
http://somesite.com/image.aspx?imageid={imageid}&format={extension}
The best solution I have found so far to convert these is UrlRewrite but we are kind of doing the opposite of what it intends (taking nice urls to nasty). I have been struggling to get the rewrite rule correct for this and was hoping that somebody could help. Below is what I currently have and am aware it may be completely wrong:
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^image.aspx?([^imageid=]+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="image/{R:1}.jpg" />
</rule>
</rules>
</rewrite>
Was able to get the basic functionality to work with the following rule.
<rule name="Redirect Category Name and Sort By" stopProcessing="true">
<match url="^image\.aspx$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="^imageid=([0-9]+)" />
</conditions>
<action type="Rewrite" url="image/{C:1}.jpg" appendQueryString="true" />
</rule>
I'm running Joomla on IIS. I've got about a dozen categories (financial newsletter publishers) that I'm using to organize about 40 articles (financial newsletters). I'm using the joomla built-in SEO so the URL's look like this:
http://www.global-autotrading.com/autotraded-newsletters/13-angel-publishing/43-options-trading-pit.html
The numbers in front of the categories and articles are annoying, and I'm not too fond of the navigation provided by a Section Layout menu item. Also, some financial newsletters don't operate under the umbrella of a publisher so I want a more flexible organization.
I've tried simply constructing a menu hierarchy (under the autotraded newsletters menu) that has some newsletters directly under the parent menu item, and some publishers with their newsletters as menu items underneath them. However, that was causing some links to break; clicking on a link would take me to the wrong article, and what not. Thus, it seems like using a hand-coded menu structure is not compatible with using another, "parallel" section-layout view of the content.
Thus, I've decided to get rid of the idea of using categories to organize that content. I'm going to create an article for each "publisher" category. I'll manually add links to each publisher's newsletters in that publisher's article. I'll also create a parallel menu structure like I was describing above.
Anyway, that's a lot of background info, with the hope that I'll get some confirmation that I'm not doing something fundamentally flawed.
The problem is that there are external sites linking directly to some URLs like above. I don't want these links to break (classic SEO problem, I believe). I think the solution is to use 301 redirects to (for example) redirect from:
http://www.global-autotrading.com/autotraded-newsletters/13-angel-publishing/43-options-trading-pit.html
to
http://www.global-autotrading.com/autotraded-newsletters/angel-publishing/options-trading-pit.html
or from
http://www.global-autotrading.com/autotraded-newsletters/4-10-percent-per-month/12-10-percent-per-month.html
to
http://www.global-autotrading.com/autotraded-newsletters/10-percent-per-month.html
There are various guidelines around for creating 301 redirects in IIS (ex: http://www.webconfs.com/how-to-redirect-a-webpage.php), but I was wondering if these are compatible with Joomla, particularly with Joomla with the SEO features turned on.
Also, if it seems like I'm doing something fundamentally wrong, please let me know :)
Thanks!
Here is the rewrite section of a web.config file that works. The trickiest part was to figure out that the redirect rules need to preceed the SEO rules in the web.config
<rewrite>
<rewriteMaps>
<rewriteMap name="StaticRedirects">
<add key="/old-url-1.html" value="new-url-1.html" />
<add key="/old-url-2.html" value="new-url-2.html" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Security Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="(\<|%3C).*script.*(\>|%3E)" />
<add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
</conditions>
<action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="Redirect Rule" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="False" redirectType="Permanent" />
</rule>
<rule name="SEO Rule">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
<add input="{URL}" negate="true" pattern="^/index.php" ignoreCase="false" />
<add input="{URL}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
Code similar to this was recently included in the default Joomla install starting at version 1.6.2.
It is important that all external redirects are listed before any internal rewrites, otherwise the rewritten pointer will be inadvertently exposed back on to the web as a new URL.