I have the following code in my htaccess file:
Redirect /produkte/category/subcategory/ https://www.newsite.com/category/subcategory
Redirect /produkte/category/subcategory/product/ https://www.newsite.com/category/product
the first line works ok, but the second line is redirected to combination of lines:
https://www.newsite.com/category/subcategoryproduct
this example is one of the simple ones, but there is some more complicated links, how can I make each of line considered separately from the previous lines?
Thanks for all,
solved with:
RewriteCond %{QUERY_STRING}
RewriteRule ^/produkte/category/subcategory/$ https://www.newsite.com/category/subcategory? [R=301,NE,NC,L]
RewriteCond %{QUERY_STRING}
RewriteRule ^/produkte/category/subcategory/product/$ https://www.newsite.com/category/product? [R=301,NE,NC,L]
Related
I cannot find a way to combine these 3 lines into one line, as a catch all for the url parameter "displayby".
The following 3 lines work, if the value is either price, date or menu_order but does anyone know how to write a directive that will catch all three of them, or even more? - as in any variable?
On the site different pages have example displayby=price, so as the examples work before, they need to redirect to the original URL - i.e.
www.example.com/category/kits/?displayby=price
to
www.example.com/category/kits/
Here is the code:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^displayby=price$
RewriteRule ^category/kits/$ https://www.example.com/category/kits/? [L,R=301]
RewriteCond %{QUERY_STRING} ^ displayby=date$
RewriteRule ^category/kits/$ https://www.example.com/category/kits/? [L,R=301]
RewriteCond %{QUERY_STRING} ^ displayby=menu_order$
RewriteRule ^category/kits/$ https://www.example.com/category/kits/? [L,R=301]
The above works perfectly, but how can I combine these into one directive that will catch all?
I do thank you in advance for your assistance.
Update
Better yet, if any URL that has a URL paramter of that type "displayby=*" can it be redirected to the URL it's attached to. Specifically for displayby.
Thank you
Try
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^displayby=(.*?)$
RewriteRule ^category/kits/$ https://www.example.com/category/kits/? [L,R=301]
(.*?) should regex match any value here without being too greedy
I have looked and keep finding really similar solutions and I managed to get it working halfway.
Solved first half:
entered url: wildcard.domain.com points to domain.com/wildcard (and doesn't change url) GREAT!
the .htaccess file code below does this.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.pagebyme\.com$ [NC]
RewriteCond %{REQUEST_URI}::%1 !^/([^/]+).*?::\1
RewriteRule ^(.*)$ /%1/$1 [L]
Problem 2: if entered url is wildcard.domain.com/admin shows wildcard.domain.com/wildcard/admin
I don't want wildcard to show the second time. I just want the url to be wildcard.domain.com/admin
What rule do I need to add?
This is my first time using stackoverflow. Thanks in advance.
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
I have these links in my website:
www.example.org/folder/files.php?file=folder/document.pdf
www.example.org/folder/files.php?force&file=2009.pdf
and I want redirect to :
www.example.org/files/folder/document.pdf
www.example.org/files/2009.pdf
I tried :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^files/(.*)$ /files.php?file=$1 [R=301,L]
</IfModule>
but doesn't work!
any help?
RewriteRule ^files/(.*)$ /files.php?file=$1 [R=301,L]
There are two issues with this rule ... first, what you are matching needs to appear first in the rule, then what you are rewriting appears second - you have that backwards.
Once you reverse that, though, you run into the second issue - you can't match query strings in a RewriteRule, you need to match them in a RewriteCond:
To match www.example.org/folder/files.php?force&file=2009.pdf and redirect it to www.example.org/files/2009.pdf you would do:
RewriteCond %{QUERY_STRING} ^force&file=(.*)$ [NC]
RewriteRule ^folder/files.php$ /files/%1 [R=301, L]
The %1 matches what's in the parentheses in the RewriteCond.
Search on google first. The first thing displayed on google for htaccess is htaccess redirect. I think
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html (same line with a space) should work. Go to http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F . Php would also do the work. Just goolgle things before asking them.
I am trying to rewrite all the old oscommerce links to a new website. But I am having trouble with part of the URL I need to rewrite.
The link looks like this:
http://www.domain.com/product_info.php?cPath=3_72&products_id=129&osCsid=6j3iabkldjcmgi3s1344lk1285
This rewrite works for the above link:
RewriteCond %{REQUEST_URI} ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129&osCsid=([A-Za-z0-9-_]+)$
RewriteRule ^(.*)$ http://www.domain.com/apple/air.html? [R=301,L]
But will not work for:
http://www.domain.com/product_info.php?cPath=3_72&products_id=129
My problem is that I want the rewrite to work no matter if the &osCsid=6j3iabkldjcmgi3s1344lk1285 part is included or not.
I think you can achieve this by not specifying the closing delimiter ($)
Give this a try:
RewriteCond %{REQUEST_URI} ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129
RewriteRule ^(.*)$ http://www.domain.com/apple/air.html? [R=301,L]
By not putting the $ at the end of the regex string you are basically saying: match any string that starts with ..., no matter what comes after
Hope this helps :)
This should do the job just fine:
RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129
RewriteRule ^product_info\.php$ http://www.domain.com/apple/air.html? [R=301,L]
There is no need for separate condition RewriteCond %{REQUEST_URI} ^/product_info\.php$ -- this part can be (actually, SHOULD BE, for better performance) moved to RewriteRule.
This is enough ^cPath=3_72&products_id=129 -- it tells "When query strings STARTS with ...". No need to include optional/non-important parameters osCsid=([A-Za-z0-9-_]+).
This rule is to be placed in .htaccess file in website root folder. If placed elsewhere some small tweaking may be required.