Just in need of some assistance with some redirects.
I have the following url I need to remove the ending number from:
http://www.testsite.com/category/subactegory/this-product-name-12966.html
So it becomes:
http://www.testsite.com/category/subactegory/this-product-name.html
I have tried the following but cant quite crack it.
RedirectMatch 301 ^-([0-9]+).html http://www.testsite.com/$1.html
Any help would be greatly appreciated
Brendan
Actually your regex is little incorrect. Try this:
RedirectMatch 301 ^/(.+?)-([0-9]+)\.html$ /$1.html
Related
I am trying to run a bunch of 301 redirects using an .htaccess file. However my rules are not working. I'm not sure what I'm doing wrong.
Here is my rules:
RedirectMatch 301 /directory/1 http://www.example.org/newdirectory
RedirectMatch 301 /anotherdirectory/2/3 http://www.example.org/newdirectory
If I visit www.example.org/directory I get redirected to the correct place. However if I visit www.example.org/directory/1 I do not get redirected. It seems to only work when there is just 1 level if I try to add more levels it stops working
Is there an issue with using "/" in the match? Should I try a regex expression instead of the actual path?
Please anyone can shed some light on this?
I have http://domain.com/frame/1234sdfs but I want to change it to http://domain.com/#/frame/1234sdfs
I'm using trial and error at the moment and getting nowhere with the following in my .htaccess
RedirectMatch 301 ^/frame/([^/]*)$ /#/frame/$1
Could someone place me in the right direction? I have been using http://htaccess.madewithlove.be/ to try get the output URL as expected but can't figure it out.
You should use mod_rewrite so that you can use the NE flag. It's probably being converted to %23 using mod_alias. You need to send it literally with this code here.
RewriteEngine On
RewriteRule ^frame/([^/]+)/?$ /#/frame/$1 [NE,L,R=301]
Omitting the [NE] will result in the # being converted to its hexcode
equivalent, %23, which will then result in a 404 Not Found error
condition.
https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_ne
Note: Makes sure .htaccess is allowed and mod_rewrite is enabled.
I need to remove anything on the end of URLs like the below examples without the /68 or any number ID
https://www.website.com/forum/making-coffee/68 <-- I would like to remove the / and anything after so it looks like this below.
https://www.website.com/forum/making-coffee
I've searched but can't get the redirect to work correctly.
Any idea?
You can use this rule in your root .htaccess
RedirectMatch 301 ^/(.+?)/[0-9]+$ /$1
I am moving a site from IIS to Apache and part of the transition requires a change in URL handling.
The current URL pattern is:
http://example.com/articles/tabid/110/ID/1691/simple_friendly_name_of_page.aspx
1691 is the unique id of the post. It consists of two or more digits.
I would like to use .htaccess so as to ignore the "simple_friendly_name_of_page.aspx". Please bear in mind that the aforementioned aspx page can contain UTF-8 characters above the ASCII range (Hebrew, Greek etc)
In essence, I would like to permanently (301) redirect requests for
http://example.com/articles/tabid/110/ID/1691/simple_friendly_name_of_page.aspx
to
http://example.com/articles/tabid/110/ID/1691
I imagine that this has to do with
RedirectMatch 301 http://example.com/articles/tabid/110/ID/(.*)/(.*)
but I cannot grasp the regex needed for the other part of redirect / mod-rewrite.
Any help would be much appreciated.
Thanks in advance!
RewriteEngine on
RewriteRule ^articles/tabid/([0-9]+)/ID/([0-9]+)/(.*)$ articles/tabid/$1/ID/$2 [R=301]
or
RedirectMatch 301 ^/articles/tabid/([0-9]+)/ID/([0-9]+)/(.*)$ http://example.com/articles/tabid/$1/ID/$2
I am moving content on a previous website where 2 copies of the site were made to translate it so that i only have one remaining.
To provide fallback access, i wrote this rewritematch rule :
RedirectMatch 301 /(en|fr)/(.+)\.php\??(.+)? /$2.php?locale=$1&$3
But it doesn't seem to be working.
If i do the following instead, everything works fine but i lose the query string passed in the original link which i really want.
RedirectMatch 301 /(en|fr)/(.+)\.php /$2.php?locale=$1&$3
Is there something i am doing wrong? Or are query strings not supported? (I checked but there seems to be no limitations on the apache docs).
Thanks in advance for your help!
try
RedirectMatch 301 /(en|fr)/(.+)(\.php\?)?(.+)?