RewriteRule url with a parameter to a new url with same parameter - apache

With .htaccess I want to create a URL forwarding from
www.example.com/en/?instance_id=1083&lang
to
www.example.com/en/Veranstaltung/1083/
You can see, that the id is the same, it is possible?
The "en" in the url may change, it shouldn't be a problem.
I tried some different things, like this:
RewriteEngine on
RewriteCond %{query_STRING} instance_id=(.*)$$
RewriteRule ^(.*)$ /$1? [R=301,L]
But it didn't work.
I hope, you can help me. I have googled & checked other sites, I haven't been able to find a solution.
If you need more information, only ask me. Its my first question here.
Added the original links here:
http://dorfbladl.com/en/ <-- this is the page
If you press one entry of the calendar on the right side, it should be forwarded to
http://dorfbladl.com/en/Veranstaltung/1914/
This url is one example, the id changes with every entry.
Maybe it could be useful, to find the solution.

You can use the following :
RewriteEngine on
RewriteCond %{QUERY_STRING} instance_id=([^&]+)&lang
RewriteRule ^(.*)$ /en/veranstaltung/%1? [R=301,L]

Related

Htaccess rewrite with parameter value

I'm looking for some help. I wanted to redirect the following paramters to another url, how can I make this possible? I have googled alot of other solutions but I fail to make this one work.
https://(www).website.com/reservation#!/confirm?code=a1XapXsCmlaC0
to
https://new-website.com/test/page#!/confirm?code=a1XapXsCmlaC0
Attempted code:
RewriteRule \/reservation#!\/confirm\?code=$ https://test.com/$1
"grep"-ing the code value would make it much easier.
Any help is much appreciated.
Thanks in advance
You may use this redirect rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.com$ [NC]
RewriteRule ^reservation/?$ https://test.com/test/page [L,NC,R=301]
Query string and fragment i.e. part after # will automatically be forwarded to the new URL.
Based on your shown samples, could you please try following. Where you want to redirect from (www).website.com to new-website.com in url.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*) [NC]
RewriteRule ^ https://new-%1/test/page#!%{REQUEST_URI} [QSA,NE,R=301,L]

htaccess only one file in subfolder and keeping the url

I need to put files in a new folder like this:
domain.com/newsite/newpanel/events.php
There are other files in the server like:
domain.com/events.php,
domain.com/oldsite/events.php etc.
Requirement 1:
I cannot redirect everything (because old implementations exist) with generic rules,
so I only want to redirect specific urls.
domain.com/events should now skip the old files and go to domain.com/newsite/newpanel/events.php
Requirement 2:
I tried something like this
RewriteRule ^events /newsite/newpanel/events/$1 [P]
but the url on the url bar will change. Is it possible for it to display domain.com/events?
thank you all!
EDIT: Since OP has mentioned different URLs in comments section so adding solution as per that here.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/CProjects/events/?$ [NC]
RewriteRule ^(.*)$ CProjects/folderA/folderB/events [L]
Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs after putting these Rules into your .htaccess file.
RewriteEngine ON
RewriteCond ^/events/?$ [NC]
RewriteRule ^(.*)$ newsite/newpanel/events.php [L]

Redirecting Dynamic Url to Static Url

I have read a lot of suggestion, article but i could not fixed my problem. Here is my Url :
us/my-blog?catid=1&id=404:my-thought-of-the-day-problem-of-traditional-education
ja/resources?id=366:video-clip
I want to redirect this URL to static URL. I have tried with .htaccess Like this :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI}
(/|.php|.html|.htm|.feed|.pdf|.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Redirect 301
/tw/en/investment-opportunities/ultimate-banking-how-to-create-your-own-bank
http://takeshiyashima.com/tw/investment-opportunities/ultimate-banking-how-to-create-your-own-bank
Above URL Fixed and working now but the top URL i have mentioned are not working. I need help.
Please, give a more clear example and post the right link, as it is not clear if there is any symbol before 'ja/resources' and if it's a part of the link at all.
As I understand you want to take only the part:
'my-thought-of-the-day-problem-of-traditional-education'
and redirect to: 'http://takeshiyashima.com/tw/investment-opportunities/my-thought-of-the-day-problem-of-traditional-education'
If it's true here is the possible rule:
us/my-blog?catid=1&id=404:my-thought-of-the-day-problem-of-traditional-education
RewriteRule ^\/?us/my-blog\?catid=\d+id=\d+\:(.*) http://takeshiyashima.com/tw/investment-opportunities/$1 [R=301,L]
Not tested and can be made shorter. If you give more details to the example I will try to help.
Update according to your comment
For ja/resources?id=366:video-clip to takeshiyashima.com/ja/resources it is:
RewriteRule ^\/?ja/resources.* http://takeshiyashima.com/ja/resources [R=301,L]
For 'us/my-blog?catid=1&id=404:my-thought-of-the-day-problem-of-traditional-educatio‌​n', everything is clear, but I see no logic in '/1-my-thought', we have to have a clear pattern. If you say that
you want to take always first 2 words from 'my-thought-of-the-day-problem-of-traditional-educatio‌​n'
then we can make '/1-my-thought', but if you will have different strings like 'my-stuff-education-is-cool', then we will not be able to apply a pattern using regular expressions. Please, provide more original links (3+) you would like to change, so I can see if there is any pattern.
If there is no pattern at all it is possible to use, for example, RewriteMap for Apache with an additional script on the server side, which will handle your links, but it's a more complex way, so let's stick to regular rewrites for now. Waiting for 3+ more examples.

.htaccess question - redirects after the domain name

Apologies if this is answered elsewhere. I had a search for this on here, but I'm quite confused so I'm not 100% what to search for in the first place.
I have a Wordpress site which is at exampledomain.com. I also own exampledomain.co.uk, and I have put in the .htaccess file the follow lines:
RewriteCond %{http_host} ^exampledomain.co.uk [nc]
RewriteRule ^(.*)$ http://exampledomain.com/$1 [r=301,nc]
These work fine in terms of changing exampledomain.co.uk to exampledomain.com, but the moment I add in something after the exampledomain.co.uk (i.e. exampledomain.co.uk/page1) the .htaccess file doesn't change it so it tries to load.
Is there something I can add to the .htaccess file which will sort this, so that, for example, if I were to type exampledomain.co.uk/page1 it would redirect to exampledomain.com/page1 ?
Thanks,
Charlie
P.S. Apologise for the weirdly parsed example links, but as a new user it won't let me include more than two hyperlinks.
Why not simply do
RedirectPermanent / http://exampledomain.com
in the co.uk's config instead? mod_rewrite is very handy, but for a simple domain redirector, it's major overkill.
comment followup:
I'd go for something like this:
RewriteCond %{HTTP_HOST} exampledomain.co.uk$ [NC]
RewriteRule (.*) http://exampledomain.com/$1 [R=301,L]

trying to get mod_rewrite to work

I have this problem where I switched CMS from the old one to the new one so I am trying to redirect urls properly.
Here are some example urls I wanted to convert:
#-1) http://www.mysite.com/?dispatch=search_data&features=hash_tag
#-2) http://www.mysite.com/index.php?dispatch=search_data&features=hash_tag
Basically both of them are identical except the first one doesn't have index.php in the url.
I got the following to code to partially work:
RewriteCond %{QUERY_STRING} dispatch=(.*)
RewriteRule ^$ http://www.mysite.com/? [L,R=301]
The above code works for #-1 (when there is no index.php) but when there is index.php it doesn't work.
Any help / guidance is much appreciated.
Thanks
____________UPDATE_______________
As per request, here is what the the target url should be:
http://www.mysite.com/
What do you mean it "works"?
You should probably post an example of what you want the new url to look like given the old url.
But in any case, part of your problem is that the RewriteRule line is specifically excluding index.php and any other page on your site.
What you wrote basically tranlates to this:
if the query string contains "dispatch=...":
redirect requests FOR THE HOME PAGE ONLY (^$) to http://www.mysite.com/
RewriteCond %{QUERY_STRING} dispatch=(.*)
RewriteRule ^(index.php)?$ http://www.mysite.com/? [L,R=301]
have you tried changing the second part to include the "index.php" part?
RewriteRule ^$ http://www.mysite.com/index.php? [L,R=301]