How to rewrite a URL using htaccess?

I am still having a problem with my re-write rule My objective is to remove a certain directory from a URL, how do I achieve this? For example: www.mywebsite.com/uk/editions/  should be re-written to  www.mywebsite.com/editions/ ( removing the directory UK )

  • The above scenario is now working for all URLS, except one. The UK homepage is physically located here. ( index.html) http://www%20.mywebsite.com/uk/ And the correct re-write rule should display the URL as http://www%20.mywebsite.com instead it is showing the www root index.html instead of the uk/index.html page. BUT if I specify the index page within the URL like so http://www%20.mywebsite.com/uk/index.html it correctly rewrites the URL to http://www%20.mywebsite.com  and shows the UK index page and not the www root index page. The rule I am using is as follows. ------------------------------------------ I am not sure what I am doing wrong. Here are my rule(s). Thanks                  <rule name="Hide UK Directory in URL" enabled="true" stopProcessing="true">                     <match url="^uk$|^uk/(.*)$" />                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">                         <add input="{HTTP_HOST}" pattern="^www\.mywebsite\.com$" />                     </conditions>                     <action type="Redirect" url="{R:1}" logRewrittenUrl="true" />                 </rule>                              <rule name="Rewrite the URL after UK is hidden" enabled="true" stopProcessing="true">                     <match url="^(?!uk)(.*)" />                     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">                         <add input="{HTTP_HOST}" pattern="^www\.mywebsite\.com$" />                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />                     </conditions>                     <action type="Rewrite" url="uk/{R:1}" logRewrittenUrl="true" />                 </rule>

  • Answer:

    You should try http://stackoverflow.com for this kind of questions.

Giovanni Olivera at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.