I am using urlrewriter.net and I am trying to make a redirection. So here is the condition,
If the requested url doesn't end with a / (slash) and
then add / at the end of the url and
redirect to added url.
So if the url is "http://www.something.com/cases" then add / and redirect it to "http://www.something.com/cases/"
I've used code but it didn't work out for me :
<if url="^~/(.+)(/){0}$">
<redirect url="~/(.+)" to="~/$1/$"/>
</if>
I am going to answer my own question here :
I've accomplished this by using this way :
<unless url="^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js|\.aspx|\.ashx|\.ascx|\.shtml|\.html|\.htm)(\?.+)?)$">
<if url=".+(?<!/)$">
<redirect url="(.+)" to="$1/"/>
</if>
</unless>
If url doesn't end with "/" then it will be redirected to the one which has "/" at the end.
I hope it helps everyone out there.
Can you use the URL Rewrite 2.0 module? You can easily add it there, because the rewrite template for that rule is a built-into the GUI.
Related
How to Redirect
Old Link:
http://www.astrokapoor.com/products/gems/gemstones/ruby-manik-new-burmees/ (this is custom php/html site)
New Link- http://astrokapoor.com/en/ruby-manik-gemstone/ (this is wordpress site link)
I used below code but no success
RewriteRule ^/products/gems/gemstones/ruby-manik-new-burmees /en/ruby-manik-gemstone [L,R=301]
Let's assume both the source and the target reside in the different virtualhosts and that you are defining this in VirtualHost context. Let's also assume you are the admin of the site and you have no reason to define this in .htaccess context.
All you need is a Redirect directive in the source virtualhost:
Redirect /products/gems/gemstones/ruby-manik-new-burmees/ http://astrokapoor.com/en/ruby-manik-gemstone/
This will redirect /products/gems/gemstones/ruby-manik-new-burmees/ and all subpaths from it to the new url, such if someone requests:
Host: www.astrokapoor.com
GET /products/gems/gemstones/ruby-manik-new-burmees/something
they will get redirected to:
http://astrokapoor.com/en/ruby-manik-gemstone/something
Note: Redirect belongs to mod_alias. In such simple redirection cases you should avoid mod_rewrite. Use mod_rewrite only when you have no other choice.
Add this line in your old page html page.
<meta http-equiv="refresh" content="0; url=http://astrokapoor.com/en/ruby-manik-gemstone/" />
By using simple redirect plugin You can set your redirect links easily by define each URL to match each page.
Try to use this code in .htaccess file.
RewriteRule ^products/gems/gemstones/ruby-manik-new-burmees/$ http://astrokapoor.com/en/ruby-manik-gemstone/ [L]
RewriteRule ^sunsign/aquarius%4027.html/$ http://www.astrokapoor.com/en/Aquarius-sunsign/ [L]
I need to remove /web/guest/ from all urls on a portal via nginx.
Currently urls looks like this:
www.mywebsite.com/en/web/guest/blog-information
www.mywebsite.com/en/web/guest/something-else/information2
www.mywebsite.com/en/web/guest/blog-information3
and so on....
Should be:
www.mywebsite.com/en/blog-information
www.mywebsite.com/en/something-else/information2
www.mywebsite.com/en/blog-information3
and so on....
What should I add in nginx.conf in order to make this change work ?
This can be done with nginx rewrite, try add a rule like this:
rewrite ^(.*)/web/guest/(.*)$ $1/$2 permanent;
This will remove the last /web/guest/ in your uri, you can write a more specific rewrite rule depending on your situation.
The last parameter given above is an optional flag, permanent is for 301 redirection and redirect is for 302, there are also other options so you'd better read the docs for more detailed information.
I have a wordpress website and a I need rewrite:
myurl.com/name-of-my-post/?lang=es
To
myurl.com/es/name-of-my-post/
I allready try everthing that i can found but not is working
P.S I don't need send the lang parameter to index.php becausa there is a plugin that reply to
myurl.com/es/name-of-my-post/ but not rewrite when a visit come from myurl.com/name-of-my-post/?lang=es
Thanks for the help
A simple fix (which may not work because it is too simple) is to permanently redirect any URI with a lang parameter:
if ($arg_lang) {
return 301 /$arg_lang$uri;
}
See this caution on the use of the if directive.
I recently moved a subdomain to my main domain but I also changed the url structure.
Previously I had pages like http://sub.domain.com/companies/my-company-id/year/2012/charts
When moving to the main domain, I removed all the complicated urls to juts get:
http://www.domain.com/companies/my-company
I currently have the following rule:
rewrite ^/companies/(.*)$ http://www.domain.com/companies/$1 permanent; but when someone go on a page like http://sub.domain.com/companies/my-company/2012/charts they get redirect to http://www,.domain.com/companies/my-company/2012/charts and get a 404.
I like to force a redirection to http://www,.domain.com/companies/my-company-id regardless of what's after the my-company-id
Currently the parameter $1 is having the entire URI after /companies, so you are getting redirected to the original path. You should only extract the company-id in $1.
Use this:
rewrite ^/companies/(.*)/(.*)$ http://www.domain.com/companies/$1 permanent;
Here the rest of the URI after company-id will be available in the parameter $2, which is not needed in the rewrite condition.
I have a wordpress site and has template page. I am passing class ID as cid parameter. http://www.example.com/class-details/?cid=51
I want it to have like http://www.example.com/class-details/
I wrote rule below in .htaccess
RewriteRule ^class-details/?([^/]*)$ example.com/class-details/$1 [NC,R,L]
It leads to recursive redirection. I tried checking wordpress redirect API a lot. but no luck. Please guide me for this.
Better to create custom post type, then you don't need to pass the cid or anything and you will have Rewrite URL.
try this
<rule enabled="true" match-type="wildcard">
<from casesensitive="true">/class-details/cid=([a-zA-Z0-9]+)$</from>
<to type="passthrough">/class-details?cid=$1</to>
</rule>