I want to create some userfriendly new redirects for my website.
My internal search pattern is the following : website.com/search/stuff
I want to add in my htaccess a rule that would redirect : /search=stuff
to : /search/stuff
I was trying the following code into my htaccess file :
RewriteCond %{QUERY_STRING} \\search=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]
But that doesnt seem to work... any ideas of where I may be wrong?
Thanks !
Related
I want to 301 redirect a specific path to another subdomain with htaccess
I want :
A : http://www.example.org/markets/access/id/56
B : http://www.example.org/markets/market/id/56
to redirect to :
A : https://archive.example.org/markets/access/id/56
B : https://archive.example.org/markets/market/id/56
I have tried this but get an error 500:
RewriteCond http://www.example.org/markets/(.+?)
RewriteRule https://archive.example.org/markets/$1 [R=301,L]
Thank you
Based on your shown samples, could you please try following. Please make sure you put these rules at the top of your .htaccess file.
Also make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.(example\.org)$ [NC]
RewriteRule ^ https://archive.%1%{REQUEST_URI} [NE,R=301,L]
I'm trying to change my url using htaccess file.
my url is : http://localhost/shasi/payment-result?Authority=000000000000000000000000000023436395&Status=NOK
and i want to redirect my page to this url : http://localhost/shasi/payment-result/Authority/000000000000000000000000000023436395/Status/NOK
How can i do this ?
RewriteCond %{QUERY_STRING} ^Authority=([0-9]+)&Status=([^/]+)$
RewriteRule ^payment-result /payment-result/Authority/%1/Status/%2 [R=301,L,NC]
I'm using a .htaccess file for the first time with MAMP servor, and I'm trying to do something simple :
I want this link : http://localhost:8888/My_app/ redirect on : http://localhost:8888/My_app/Pages/ .
I did these on .htaccess file, located on /Application/MAMP/htdocs/My_app/ :
RewriteEngine On
RewriteRule ^$ http://localhost:8888/My_app/Pages [L,R=301]
This work, but it simply redirect the user. I want to see the first url http://localhost:8888/My_app/ and not http://localhost:8888/My_app/Pages in my browser, like a 'pointer' on this page, is it possible ?
Thanks !
Updated -
So it work great with this code :
RewriteEngine On
RewriteRule ^/?$ http://localhost:8888/My_app/Pages/ [L]
But I have forgotten something in my question, how to do the same for each file in this folder ? If I want http://localhost:8888/My_app/dashboard.php pointed on http://localhost:8888/My_app/Pages/dashboard.php ?
You can just use this rule:
RewriteEngine On
RewriteRule ^((?!Pages/).*)$ /Pages/$1 [L,NC]
Assume that I have some URL like these:
http://mydomaindotcom/abc/123-link.html
http://mydomaindotcom/abc/page/page-link.html
Now I want to redirect all URLs like : http://mydomaindotcom/otherstring/123-link.html to http://mydomaindotcom/abc/123-link.html
or http://mydomaindotcom/anotherone/page/page-link.html to http://mydomaindotcom/abc/page/page-link.html
It means that the first segment on URL must be [abc], if not, redirect to the [abc]-beginning one.
How can I do this?
Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/abc/ [NC]
RewriteRule ^[^/]+/(.*)$ /abc/$1 [R=301,L,NC,QSA]
I've removed and/or combined a couple of pages on a site, And now I need to set up a 301 redirect.
I thougt doing so in my .htaccess was my best bet, but the rules I trying to add doesen't get noticed or something. They don't respond at all...
These are the rules I've tried so far:
Redirect 301 /?Page=sPage&sPage=Our-Store %{SERVER_NAME}?Page=sPage&sPage=About-Us
RewriteRule ^/?Page=sPage&sPage=Our-Store$ %{SERVER_NAME}?Page=sPage&sPage=About-Us[R=301,NC,L]
RewriteCond %{HTTP_HOST} !^%{SERVER_NAME}$ [NC]
RewriteRule . %{SERVER_NAME}%{REQUEST_URI}?Page=sPage&sPage=About-Us [R=301,L]
This last one messed up the CSS and JS src's...
I have this at the top:
RewriteEngine On
RewriteBase /
Any suggestion?
UPDATE : follow up question
I have like 3000+ equal url strings with an ending ID that is different. How do I redirect all those requests?
This is the old url : ?Page=Tuninglist&Car=*
And this is the new one : ?Page=Tuning&view=vehicle&type=Car&id=*
* The value of id= is just integers...
Was hoping something like this could work, but no - got a 500 server error instead...
RewriteCond %{QUERY_STRING} ^Page=Tuninglist&Car=([0-9]+)$
RewriteRule ^ ?Page=Tuning&view=vehicle&type=Car&id=$1 [R=301,L]
*EDIT: The 500 server error occurred because I had a ? at the beginning of the condition.
The redirect now works, but the ending id value doesn't get included.
All I get is the correct page, but not the associated content based on that id...
You can't match against the query string in a redirect or rewrite rule, you need to do it using the %{QUERY_STRING} variable in a condition:
RewriteCond %{QUERY_STRING} ^Page=sPage&sPage=Our-Store$
RewriteRule ^ %{REQUEST_URI}?Page=sPage&sPage=About-Us [R=301,L]