Came accross a strange bug that is starting to play on my nerves.
So I have a huge .htacces file with a lot of redirection which is actually working.
Im starting to think this file need to be compiled...
Those are examples of working one :
#redirection des liens morts 9/11/15
RedirectPermanent /rappel.html http://www.agencedevoyage.com
RedirectPermanent /mail.html http://www.agencedevoyage.com
And those one are not working.. Why is that ? Is it due to special characters ?
#redirection des liens morts 22/12/15
RedirectPermanent /voyage/asie/vi%C3%AAt-nam/ http://www.agencedevoyage.com/voyage/asie/vietnam/
RedirectPermanent /voyage/asie/viêt-nam/ http://www.agencedevoyage.com/voyage/asie/vietnam/
Any help gladly appreciate.
Edit :
Half Solution
So I manage to do it by using this rule :
RedirectMatch 301 /voyage/asie/vi.*t-nam/?$ http://www.agencedevoyage.com/voyage/asie/vietnam/?continent=asie&country=vietnam&type=voyage
But this is clearly not really what I want since the idea was to minimise the number of link...
You can use these rules at top just below RewriteEngine On:
RewriteEngine On
RewriteCond %{THE_REQUEST} /voyage/asie/vi\%C3\%AAt-nam/? [NC]
RewriteRule ^ /voyage/asie/vietnam/? [L,R=302]
RewriteCond %{THE_REQUEST} /(rappel|mail)\.html [NC]
RewriteRule ^ /? [L,R=302]
Related
It's been a while since I've been busting my head to do a htaccess rewrite.
I would like to redirect all the pages from example.com/en/XXX to example.com/en.
I'm doing either redirection loops or errors 500.
Is it possible to help me to find the right formula?
I tried RewriteRule ^en/(.+)$ /en/ L,QSA
also this RewriteRule ^/en\/.*$ http://example.com/en/$1 [R=permanent,L]
Do you also know good links to learn htaccess and rewrite?
thank you in advance for your help
You need to put a condition to stop Looping, could you please try following once, base on your shown samples only.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/en/.*/?$ [NC] [L]
RewriteRule ^(en)/.*$ http://example.com/$1 [NC,L]
Merci RaVinder pour ton aide ! <3
I'd like to create some kind of redirection script using .htaccess to map short urls (like example.com/1 to other urls). To do so, I've created this:
RedirectPermanent /1 https://www.youtube.com/watch?v=...
RedirectPermanent /2 https://www.youtube.com/watch?v=...
So far, that's working. However, it's missing a fallback. I'd like to add a 404 page that is shown whenever someone tries to navigate a URL that doesn't have any redirect (yet).
I've tried adding this:
...
RewriteCond %{REQUEST_URI} !^/404.html$
RewriteRule .* /404.html [L,R=302]
Obviously, this isn't working, because now ALL calls are redirected to 404.html. I thought about adding the redirects as conditions, but since there might be many redirects that approach seems very bad to me.
What can I do instead?
Thanks for helping out.
I've done this now, but I'm not sure if this is the best solution.
Please comment if you have any advices.
RewriteRule ^/1$ https://www.youtube.com/watch?v=1 [L,R=301]
RewriteRule ^/2$ https://www.youtube.com/watch?v=2 [L,R=301]
RewriteCond %{REQUEST_URI} !^/404.html$
RewriteRule .* /404.html [L,R=302]
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'm trying to do the following...
Original path that needs to be rewritten, renamed, or redirected:
http://www.example.com/_plugin/notifications/
to:
http://www.example.com/notifications/
via root htaccess file...Any help would be greatly appreciated!
=================================================================
This does not work:
RewriteEngine On
RewriteRule ^/_plugin/notifications$ /notifications [L]
This does not work either:
RewriteEngine On
RedirectMatch ^/_plugin/notifications$ /notifications/
This does not work either:
RewriteEngine On
RewriteRule ^notifications/(.*)$ /notifications$1 [R=301,NC,L]
=============================
EDIT
With the help of #Starkeen - I have a few follow up questions to this.
Is there a way to shorten the .htaccess file up though if lets say I
have multiple subfolders within the folder instead of writing that 1
condition and the 2 rules for each subfolder?
How would I allow subfolders of the subfolder to display? Currently it is throwing a 404 at me... :(
============
Still need help with follow-up question #1, but I believe I got question #2.
SOLUTION (I believe) to follow-up question #2:
RewriteCond %{THE_REQUEST} /_plugin/notifications/ [NC]
RewriteRule ^_plugin/notifications/(.*)$ /notifications/$1 [L,R]
RewriteRule ^notifications/(.*)$ /_plugin/notifications/$1 [L]
None of the rules you have tried are correct.
To redirect /folder/subfolder to /root/subfolder you need a permanent 301 Redirect rule something like the following :
RewriteEngine on
RewriteCond %{THE_REQUEST} /folder/subfolder/ [NC]
RewriteRule ^folder/subfolder/$ /subfolder/ [L,R]
The above will redirect http://example.com/folder/subfolder/ to http://example.com/subfolder .
You will get a 404 error if the /subfolder/ doesn't exist in the root dir. To avoid the 404 error you can rewrite the /subfolder/ uri back to its original location /folder/subfolder/ using an internal Rewrite just bellow the first one
:
RewriteRule ^subfolder/?$ /folder/subfolder/ [L]
I'm struggling with an Apache rewriterule. I need to do the following:
Redirect permanently:
http://domain.com/folder/viewer/data/settings.xml?prevent_cache=4760
to
http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml?prevent_cache=4760
I've got the code below, it works without the url parameters but I can't seem to get it to work with parameters. Am i missing something?
RewriteCond %{QUERY_STRING} ^prevent_cache=([0-9]*)$
RewriteRule ^/folder/viewer/data/settings.xml$ http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml [R=301,L]
Cheers
Shaun
The only error I can see, is the leading slash / in the RewriteRule pattern. This should be
RewriteCond %{QUERY_STRING} ^prevent_cache=[0-9]*$
RewriteRule ^folder/viewer/data/settings.xml$ /siteid/includes/themes/siteid/swfs/viewer/data/settings.xml [R,L]
You don't need to append the query string to the substitution URL, because this is done autmoatically.
When everything works as you expect, you can change R to R=301. Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.
I can. Here are the rewrite condition and rule that you're looking for:
# once per htaccess file
RewriteEngine on
RewriteCond %{QUERY_STRING} prevent_cache=([0-9]*)
RewriteRule ^folder/viewer/data/settings.xml http://domain.com/siteid/includes/themes/siteid/swfs/viewer/data/settings.xml?prevent_cache=%1 [R=301,L]
But please considered this answer about the [R=301] flag: https://stackoverflow.com/a/15999177/2007055