I cannot find a case with both sides (src and target) with parameters,
I need to make a 301 from:
www.example.com/test-test/test.html?subcats=Y&features_hash=V231
to
www.example.com/test-test/test.html?features_hash=18-231
You can try something like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^subcats=Y&features_hash=V(231)$
RewriteRule /test-test/test.html /test-test/test.html?features_hash=18-%1 [R=301,L]
Actually this can be done in one RewriteRule but this rule will be too long
You can use this rule in /test-test/.htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?/test\.html\?subcats=Y&features_hash)=V(\d+) [NC]
RewriteRule ^ /%1=18-%2 [R=301,L]
Related
How to get rid of the error that causes continuous redirection? I would like these rules to work in both directions.
RewriteEngine On
RewriteRule ^search/([a-z0-9-]+)/$ search.php?name=$1
RewriteCond %{QUERY_STRING} ^name=(.*)$
RewriteRule ^search\.php$ https://example.com/search/%1/? [L,R=301]
there's a redirection loop
you may use an environnement variable to check if your url is in a Redirection context
# redirect pretty url to real php
RewriteRule ^search/([a-z0-9-]+)/$ search.php?name=$1 [L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^name=(.*)$
# force pretty url with 301 unless in a rewrite
RewriteRule ^search\.php$ https://example.com/search/%1/? [L,R=301]
i want to redirect all links with this format
https://besthost.tn/aze/viewticket.php?tid=VARIABLE1&c=VARIABLE2
to
https://besthost.tn/client-2/?ccce=viewticket&tid=VARIABLE1&c=VARIABLE2
the VARIABLE1 and VARIABLE2 must be inchanged while the redirection.
thank you
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /viewticket.php\?tid=([^&]+)&c=([^\s&]+) [NC]
RewriteRule ^ /client-2/?ccce=viewticket&tid=%1&c=%2 [NC,L,R]
This will work from the root and identify '/aze/viewticket.php' and then the tid=X&C=X pattern for redirection:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/aze/viewticket\.php [NC]
RewriteCond %{QUERY_STRING} ^tid=(.+)&c=(.+)
RewriteRule ^(.*)$ /client-2/?ccce=viewticket&tid=%1&c=%2 [L,R=301]
The R=301 part indicates a 301 'permanent' redirect which will be cached by the browser and is required if this is a permanent change in your website (for performance reasons).
This silent redirect in htaccess:
RewriteCond %{QUERY_STRING} ^pic_id=(\d+)$ [NC]
RewriteRule ^album_showpage\.php$ /gallery/image_page.php?image_id=%1 [L]
redirect a url that looks like:
example.com/album_showpage.php?pic_id=1906
to:
example.com/gallery/image_page.php?image_id=1906
that works great. But when the URL has a parameter like:
album_showpage.php?pic_id=1906&mode=prev
or
album_showpage.php?pic_id=1906&mode=next
the redirect wont work.
Question: How to cut of any parameter after pic_id=1906
thank you
You need match against the rest of the query string.
RewriteCond %{QUERY_STRING} ^pic_id=(\d+)(&.*)?$ [NC]
RewriteRule ^album_showpage\.php$ /gallery/image_page.php?image_id=%1%2 [L]
If you don't want the mode=prev stuff to be included in the rule's target, then you can simply remove the $ instead of attempting to match against it:
RewriteCond %{QUERY_STRING} ^pic_id=(\d+) [NC]
RewriteRule ^album_showpage\.php$ /gallery/image_page.php?image_id=%1 [L]
I want to redirect
http://example.com/report?domain=dollarshaveclub.com
to
http://www.semrush.com/info/dollarshaveclub.com+%28by+organic%29
I've tried:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^?domain=$
RewriteRule ^report$ http://www.semrush.com/info/$1+%28by+organic%29 [R=301,L]
But I'm not getting anywhere...What could I try next?
You must remove the R=301, part.
This works for me:
RewriteEngine On
RewriteRule ^report$ http://www.semrush.com/info/$1+%28by+organic%29 [NC]
Found the solution finally:
RewriteCond %{QUERY_STRING} ^domain=(.*)
RewriteRule ^report(.*) http://www.semrush.com/info/%1+(by+organic)? [R=301,L]
How do i remove a query string from the end of a url?
To be more specific, this is my rewrite rule:
RewriteRule example-(.*).html$ examples/view-example.php?param1=parameter¶m2=$1&split=-
and I want this to return a 404 or a redirect to www.mydomain.com/example-one.html :
www.mydomain.com/example-one.html?param1=parameter¶m2=one&split=-
This is what i tried, it doesn't work:
RewriteCond %{REQUEST_URI} /examples/view-example\.php
RewriteCond %{QUERY_STRING} param1=parameter¶m2=(.*)&split=-
RewriteRule ^(.*)$ http://mydomain.com/example-%1.html$
I think that RewriteRule ^(.*)$ http://mydomain.com/example-%1.html$ isn't correct..
This should do the trick:
RewriteCond %{QUERY_STRING} ^param1=parameter¶m2=(.*)&split=-
RewriteRule ^/examples/view-example\.php$ http://mydomain.com/example-%1.html [R=301]
Though, I didn't understand what you wanted to do with www.mydomain.com/example-one.html?param1=parameter¶m2=one&split=-