my image real url is
http://www.example.com/images/201712/2j80owr1sgg0co00k0.jpg
but I want to show image url as
http://www.example.com/images/201712/this-is-an-image-2j80owr1sgg0co00k0.jpg
I tried a lot of combinations but they did not work. Because I need last 1 part of url seperated by (-)
Thanks for help
You can use:
RewriteEngine on
RewriteRule ^(images/\d+/)[^/]+-(.+\.jpg)$ $1$2 [NC,L]
Related
I was wondering if anyone could help me with an htaccess rule.
I have a phone directory, and the folders are based on the phone number i.e. http://example.com/go/123-456-7890. But I'm finding a lot of users are refusing to use dashes and get an error message. I was wondering if there is a simple way to parse that with htaccess so they get automatically redirected to the right url format?
i.e. if they type http://example.com/go/1234567890 or http://example.com/go/(123)456-7890 that they get moved to http://example.com/go/123-456-7890
RewriteEngine On
RewriteRule ([0-9]{3})([0-9]{3})([0-9]{4}) /go/$1-$2-$3 [R]
This only does solid numbers - I am not great # mod_rewrite but this is a start:)
These 2 rules in your root .htaccess should take care of that:
RewriteEngine On
RewriteRule ^(go)/(\d{3})(\d{3})(\d{4})/?$ /$1/$2-$3-$4 [L,NC,R=302]
RewriteRule ^(go)/\((\d{3})\)(\d{3}-\d{4})/?$ /$1/$2-$3 [L,NC,R=302]
I have a site which has a url structure like so:
url/example1/sometext
So I dont have to go through and change a crazy amount of code, can I use htaccess to do the following?
url/newword/sometext redirects to: url/example1/sometext with url/newword/sometext still shown the address bar.
I have tried some rewrites like:
RewriteRule ^(.*)example1(.*)$ url/$1newword$2 [R=301,L]
Any ideas?
As long as the "url" part is still the same, then you can just get rid of the R=301 flag:
RewriteRule ^(.*)example1(.*)$ /$1newword$2 [L]
Having a Drupal here. In that Drupal is a folder with another Drupal. So in another Drupal's .htacces the base was rewritten like this Rewrite Base /another-drupal and everything's fine.
Now, printed invitations were send to customers to look at the another Drupal via its URL adrupal.com/another-drupal. And like right now the URL stands at the end of a sentence and the dot looks like it is part of the URL. How do I redirect all users who entered the URL with a trailing dot to the correct URL without the trailing dot? And in which .htaccess do I have to do that? The parent's Drupal .htacess? Or in the another Drupal's .htaccess?
I allready tried that approach: Redirect url to home page with trailing dots, but it didn't work. Is it maybe because in that example they have two dots?
Try:
RewriteCond %{THE_REQUEST} \ /([^\?\ .]*)\.(?:\?|\ |$)
RewriteRule ^ /%1 [L,R=301]
Looks like this simple rule is all you need:
RewriteRule ^(.+?)\.$ $1 [L,R=301]
This will remove trailing period (dot) from any URL.
Sometimes a br tag is inserted into our urls when they're automatically linked from other websites. It triggers a 404 page. I want to remove that tag. For example, it looks like this:
http://www.healthyeatingstartshere.com/moti<br />vation/healthy-eating-routine
This is what I have so far to fix it, but no dice:
RewriteRule ^(.*)<br%20/>(.*)$ http://www.healthyeatingstartshere.com/$1$2 [L,R=301]
Any thoughts?
Thanks very much, Phil
Escape the space with a backslash
RewriteRule ^(.*)<br\ />(.*)$ http://www.healthyeatingstartshere.com/$1$2 [L,R=301]
I have a site with URL's like this:
http://website.com/browse/wedding-service-providers/bridal-wear-and-accessories/
I'd like to remove
/browse/wedding-service-providers
from the url each time so that the resulting URL is
http://website.com/bridal-wear-and-accessories/
Thanks for your help :)
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-c-(.*)$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]
Then url like
http://website.com/bridal-wear-and-accessories-c-3/
in this url 3 is the id of category