I have URL like this: http://example.com/apple_a/
I am using this rule:
RewriteEngine On
RewriteRule ^([^_]*)-+(.*)$ $1_$2 [L,NC]
this is replacing other URL's like http://example.com/apple/a_a/a_b to "http://example.com/apple/a-a/a-b" (underscore with dashes) but when I write "_" in first directory like this "http://example.com/apple-a/a-a/" then its throwing 404 error.
So I wants that working somehow. Please help.
Correct rule will be:
RewriteEngine On
RewriteRule ^([^-]*)-+(.*)$ $1_$2 [L,NC]
You have ([^_]*) instead of ([^-]*)
Related
We have a url mydomain.com/events that needs to include a country code just before th events folder like this mycomain.com/uk/events. The country could be any number of different codes. I want to use a RewriteRule like:
RewriteRule ^([a-zA-Z0-9-/]+)/events/*.* /events/*.*
so any any url like these will work:
mydomain.com/uk/events
mydomain.com/uk/events/index.php
mydomain.com/uk/events/list-events.php?s=12
With your shown samples/attempts, please try following htaccess rules file. Please make sure to clear your browser cache before testing your URLs. Place your htaccess file along with your domain folder(not inside it beside it).
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/([^/]*)/(?:[^/]*)/([^/]*)(/.*?\.php(?:\?[^=]+=\d+)?)?\s [NC]
RewriteRule ^ %1/%2%3 [L]
I have been battling with the following code for ages and for some reason cannot redirect the following:
/folder/htdocs/uk/images/my-image.jpg >> /folder/htdocs/images/UK/my-image.jpg
I have tried
RewriteRule ^.+/(\w){2,3}/images/(.*)$ http://%{HTTP_HOST}/folder/htdocs/images/$1/$2 [NC,L]
RewriteRule ^/folder/htdocs/([A-Za-a]{2,3})/images/(.*)$ http://%{HTTP_HOST}/folder/htdocs/images/$1/$2 [NC,L]
And a number of variations but I still have not solved it. Please can someone advise how I can do this?
I have tried redirecting it to a file - just to capture the pattern matches but again to no avail.
Have this RewriteMap defined in your Apache server config (vhost):
RewriteMap uc int:toupper
Have this rule inside htdocs/.htaccess directory (create it if it doesn't exist):
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)/([a-z]{2})/images/(.+)$
RewriteRule ^ %1/images/${uc:%2}/%3 [L,NE,R=301]
I am trying to change this url:
http://blabla.nl/download/?url=https://www.bla.com/see?v=345345&type=download
to this:
http://blabla.nl/download/?url=https://www.bla.com/see&v=345345&type=download
Using .htaccess
so the ? needs to change to an &.
at the moment i am not very succesfull fixing this.
You have to do it this way:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(url=https://www\.youtube\.com/watch)\?(v=[A-Za-z0-9]+&type=download)
RewriteRule ^/?8/downloadff/?$ /8/downloadff/?%1&%2 [R=301,NC,L]
I assume that the number 345345 is always a number an will be different all the times but the rest keeps the same.
Put this as .htaccess file on http://example.nl/ or http://example.nl/download/
Try this:
RewriteEngine On
RewriteRule ^download/?url=https://www.bla.com/see&v=345345&type=download/?$ download/?url=https://www.bla.com/see?v=345345&type=download [NC,L]
I hope it works for you.
I want to do a simple redirect so that a request for app/scans/large/as89q6dfa.jpg results in app/scans/medium/as89q6dfa.jpg, etc. The trouble is that this app will be used on a few domains with different base paths. The code I've tried keeps rewriting to the absolute base path of the site and the app is actually a variable number of folders deep on the site. Is there a generalized way to do a redirect like this, without hard-coding the base path?
Here's my file and folder scructure:
app/.htaccess
app/scans/large
app/scans/medium
So the .htaccess rules should work for:
includes/app/scans/large
inc/app/scans/large
script/engine/app/scans/large
Here's my first attempt:
RedirectMatch 301 scans/large/(.*) scans/medium//$1
Here's my second attempt:
RewriteEngine On
RewriteBase /
RewriteRule ^scans/large/(.*) scans/medium/$1 [R=301,L]
When you use the "^" caracter it means that the regex will search for the string "scans/large" in the BEGINNING of the URL.
So as the base is "/", it won't work on "includes/app/scans/large/omg" because "scans" it's not in the beginning of the string.
Try this solution:
RewriteEngine On
RewriteBase /
RewriteRule (.*)scans/large/(.*) $1scans/medium/$2 [R=301,L]
It worked perfectly with the URL:
http://www.example.com/includes/app/scans/large/omg
That redirects to:
http://www.example.com/includes/app/scans/medium/omg
You can do more tests on it here: link
You can actually get RewriteBase be determined dynamically.
RewriteEngine On
# determine BASE dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^scans/large/(.*)$ %{ENV:BASE}scans/medium/$1 [R=301,L,NC]
My current .htaccess looks like this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^[0-9]+/pos /pos/$1 [L]
Currently this will redirect a url such as example.com/234234234/pos to example.com/pos
I would like it to load the directory example.com/pos, but without losing the original URL (example.com/234234234/pos) from the address bar.
Basically, the number listed in the url can change, but I always want it to load the same path.
This rule doesn't look right:
RewriteRule ^[0-9]+/pos /pos/$1 [L]
As you're not capturing anything hence there is no $1. If you want to ignore any number before /pos then use this rule:
RewriteRule ^[0-9]+/(pos)/?$ /$1 [L,NC]
Thank you anubhava. Part of your answer helped me. I did want the numbers ignored, but didn't want them to disappear.
This is the line I needed:
RewriteRule ^[0-9]+/pos/ /pos/ [L,NC]
Did not need to capture anything at all. That is what was causing the redirect.