I have the following htaccess rule:
Redirect 301 / http://www.example.co.uk/blog/
On an old blog at http://blog.example.co.uk/ that should be redirecting ALL urls from this old blog to the new one.
However if I have anything in the path: e.g. http://blog.example.co.uk/2015/test-post then it redirects to http://www.example.co.uk/blog/2015/test-post
How do I make it so that it doesn't keep the path and just redirects to the domain.
You need to use RedirectMatch for that:
RedirectMatch 301 ^ http://www.example.co.uk/blog/
Make sure to test this in a new browser.
Or if you want to strip off any existing query string also then use mod_rewrite:
RewriteEngine On
RewriteRule ^ http://www.example.co.uk/blog/? [L,R=301]
Related
I have this code in the site's htaccess file to apply a redirect on old images but it doesn't work.
RewriteRule ^image\.axd$ /wp-content/uploads/upload%1? [L,NC,NE,R=301]
When i type these urls, it does not work. I would like also replace %2F with /
http://www.example.com/image.axd?picture=2012/1/sata-ide_lg.jpg
http://www.example.com/image.axd?picture=%2F2013%2F04%2Fmicro_sim-001-en.jpg
I would like these new urls to appear (301).
http://www.example.com/wp-content/uploads/upload/2012/1/sata-ide_lg.jpg
http://www.example.com/wp-content/uploads/upload/2013/04/micro_sim-001-en.jpg
End of the url have numbers without any separator
Given url like
example.com/productdetails/product-flowers123
needed to redirect
example.com/productdetails/product-flowers--123
can i do this with .htaccess
I already tried: RedirectMatch 301 ^/productdetails/([A-Za-z]+)$([0-9]+)$ /productdetails/$1--$2
But its not worked.
You can use this rule instead:
RedirectMatch 301 ^/(productdetails/.*?[a-zA-Z])([0-9]+)/?$ /$1-$2
Make sure to use a new browser or clear your browser cache before testing this change.
I have a requirement where I need to 301 redirect an old site URL to a new one. So the format of the URLs will be:
www.oldsite.com/test/xxx.pdf
should be redirected to
www.newsite/test/xxx.pdf.
So let's say, if someone hits www.oldsite.com/test/123.pdf, it should be redirected to www.newsite/test/123.pdf.
And 123 can be any number/name, so it should be replaceable using a RegEx.
Any idea?
Yes. This should do it:
RewriteEngine on
RewriteRule ^(test/[^./]+\.pdf)$ http://www.newsite.com/$1 [L,R=301]
To go in your root .htaccess file on oldsite.com.
This URL
http://www.example.com/news/2138-gideon-rothschild-listed-leading-lawyer-expert-guides
needs to be redirected to this URL
http://www.example.com/news/gideon-rothschild-listed-leading-lawyer-expert-guides.
Here is another example:
http://www.example.com/articles/2140-can-you-trust-your-trust
to
http://www.example.com/articles/can-you-trust-your-trust
The client wants the page id removed from the URL. Can this redirect be done in the htaccess file or do I need to do it using PHP?
Yes, it can be done using a RedirectMatch rule.
Place this rule in your site root .htaccess:
RedirectMatch 301 ^/(articles)/\d+-(.+)$ /$1/$2
The very basic rule could look like the following:
RewriteRule ^([0-9-]+)(.*)$ /$2 [L,R=301]
You would need to fine-tune it a bit if you want only news/ or articles/
I need to redirect the following URL (and NOTHING with additional URL paths after the wholesale) :
www.jedzebel.com/wholesale (or jedzebel.com/wholesale)
to the following :
www.jedzebel.com/wholesale-info/wholesale-information.html
Unfortunately, I have a folder called wholesale already and when a standard 301 redirect is in place the mod_rewrite rules are causing the all URL's with wholesale in the path to rewrite incorrectly.
I tried the following in both RedirectMatch and Redirect in .htaccess after the Joomla rewrite rules but I must have something wrong :
RedirectMatch (.*)/wholesale?$ http://www.jedzebel.com/wholesale-info/wholesale-information.html [R=301,L]
Redirect 301 ^wholesale?$ http://www.jedzebel.com/wholesale-info/wholesale-information.html
Any ideas ? I need to ONLY rewrite exactly www.jedzebel.com/wholesale ...
You can make trailing slash optional in your rule.
You can try this rule:
RedirectMatch 301 ^/wholesale/?$ /wholesale-info/wholesale-information.html
Alternative:
RewriteEngine On
RewriteRule ^wholesale/?$ /wholesale-info/wholesale-information.html [L,R=301,NC]