I have some old SWF that has fixed links inside, so I need to rewrite all the links to redirect to new site I build on Wordpress.
I actually need to redirect all links that have FID=<123> to /me_<123> (that's the permalink I created for all pages I need to redirect)
For example:
http://kavor.org.il/KavOr07/Templates/showpage.asp?DBID=1&LNGID=2&TMID=843&FID=1997
Needs to go to http://kavor.org.il/me_1997
I tried to put this in .htaccess:
^FID=([^/.]+)/?$ /me_$1 [R]
but it has no effect and also for some reason slows down the entire site loading.
I know that Wordpress has its own rewrites so maybe it's interefering.
I would be glad for some help with that I got pretty lost in all the mod_rewrite rules...
To match query string you will need a RewriteCond with %{QUERY_STRING}
Try this rule:
RewriteCond %{QUERY_STRING} (^|&)FID=([^&]+) [NC]
RewriteRule ^KavOr07/?$ /me_%1? [L,R=302,NC]
Related
By using WordPress with Divi and custom php pages/scripts I ended with urls looking like this:
https://example.com/?day=today
https://example.com/?sport=1&league=123 (1=football and 123=premier_league)
I want to make them more user and SEO friendly and rewrite them in htaccess to:
https://example.com/?day=today ==> https://example.com/today
https://example.com/?sport=1&league=123 ==> https://example.com/football/premier_league
For the "day" link I tried this code, but it doesn't work
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-z\-\_]+)?$ /?day=$1 [L,QSA,NC]
</IfModule>
For the other example with sport and league I wanted to find a solution in which I will manually add old link and new link, tried redirect 301, but I think it can't work, right?
Redirect 301 https://example.com/?sport=1&league=123 https://example.com/football/premier_league
I also tried Redirection plugin in WP, but it created Rule which destroys page and makes error 500:
RewriteRule ?sport=1&liga=123 https://example.com/football/premier_league [R=301,L]
or
RewriteCond %{QUERY_STRING} ^sport=1&league=123$
RewriteRule ^$ https://example.com/football/premier_league [R=301,L]
which gaved address: https://example.com/premier_league/?sport=1&league=123
I was also wondering if I can make it with pure php, since in PHP I can easilly get proper strings for id's of the sports and leagues. Unfortunantelly changing "?sport=1&league=32758" into "?sport=football&league=premier_league" and then clean it with rewrite in htacces is not possible right now.
I'm not expecting whole code for both problems, I believe that some directions would be enough. I browse stack and google and coudn't find any examples with links that looks like mine, so example.com/?sport=1 not example.com/page?sport=1
After further investigation I believe the problem is in the way I'm opening my custom pages. I'm using shortcodes to initiate a script and inside the script my php code is included with parameters. I think that because of that I got to this page https://example.com/premier_league/?sport=1&league=123 which was pretty close, but not working.
Now my question is how to send those parameters to proper script but not into url.
I am having to move an old custom built website to a newer WordPress site.
On the old site, the URL is https://www.example.net/index.php?product=1234567890 and I need to redirect to https://www.example.net/product_name
Each product on the old site is a number parameter, and need to redirect to text on the new site.
So I figure I'll need a separate line in the .htaccess to accomplish this, but I don't know enough .htaccess.
Thanks.
Worked it out, as RewriteCond is like an If statement and RewriteRule is like a Then statement.
RewriteCond %{QUERY_STRING} (^|&)product=1314271738($|&)
RewriteRule ^index\.php$ /product_name? [L,R=301]
Very cool!
I have a webshop in asp language that will be renewed to a php webshop. There are still many url's and links from the old webshop stored on different websites that I want to revert to the homepage of the new webshop.I'm looking for example for the correct rule to redirect the following url in my .htaccess file:
http://www.example.com/shopdisplayproducts.asp?id=15&cat=football to http://www.example.com
Could you show me this example, so I might be able to make the other redirects myself.
I have tried for example this, but without success:
RewriteRule ^shopdisplayproducts* index.php [R=301,L]
Thanks for your input
Regards,
Vicef
If you want a catch-all URL that will match regardless of the query string you could use
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^shopdisplayproducts\.asp / [L,R=301]
If you want to match the query string as well you need to add two lines
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} id=15
RewriteCond %{QUERY_STRING} cat=football
RewriteRule ^shopdisplayproducts\.asp / [L,R=301]
While testing it's better to use R=302 instead of R=301 because browsers cache 301 responses, so if you change the rule you won't see the effect because the browser is still executing the cached result. When you use 302 you don't have this problem. So start with 302 and once it works replace that with 301.
Also, please be aware that redirecting everything to the homepage of a new site is almost never a good idea in terms of SERP ranking. If there is a new URL for a certain page it's better to rewrite to that URL. If there isn't, you might want to consider just letting it 404 so search engines will just remove them from their results.
I'm on my begining of learning PHP and very first steps of .htaccess, most of my new web is about main category and few subcategories.
Here are links examples i had before working out .htaccess RewriteEngine:
example.com/index.php?cat=email
example.com/index.php?cat=about&show=some
with help of .htaccess RewriteEngine i've convered them to:
example.com/email/
example.com/about/some/
Here is part of .htaccess:
RewriteRule ^([A-Za-z0-9-]+)/$ index.php?cat=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ index.php?cat=$1&show=$2 [L]
RewriteRule ^([A-Za-z0-9-]+)$ index.php?cat=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?cat=$1&show=$2 [L]
Now problem is that most of content have inside links like: "example.com/index.php?cat=about&show=some" Changing them all is option, but anyway... is there anything else could be done? I heard of some .htaccess option that autoconverts links to format you need without changing them manualy, so all links in PHP pages will be the same, but once user gets page loaded, links will be like (example.com/about/some/) Is there anything like that, or is there any other option to leave original link without changing them all?
Cheers!
Links on your site are created with your PHP scripts, Apache with htaccess can't magically change all this links in a raw.
Now what you can do, is redirect old URL to the new ones using htaccess, with a 301 redirection.
For example, if someone click on example.com/index.php?cat=email, Apache will redirect (= the URL will be changed and there will be another HTTP request) to example.com/email/, and then rewrite this to index.php?cat=email
Add this to your htaccess :
RewriteCond %{REQUEST_FILENAME} index.php$
RewriteCond %{QUERY_STRING} cat=([a-zA-Z0-9-]+)
RewriteRule ^ http://example.com/%1/? [L,R=301]
Anyway I strongly recommend you to change the links directly in your code, because even if the solution I've just explained should works (not tested), it's not really healthy to use redirection when you can avoid them.
Long time reader first time poster.
I have read through what feels like 100's on similar posts trying to make it fit what i am trying to do.
Apologies if its been covered. I believe I have the correct code but it maybe conflicting with something else?
I have old URLs from an old ASP cart and want to 301 redirect to new magneto static pages.
There are only 5 of these URLS so don't need a bulk action.
example:
OLD URL: http://test.com.au/shopcontent.asp?type=FAQ%20and%20Terms
NEW URL: http://test.com.au/privacy-policy-cookie-restriction-mode
I know that from reading other posts you can not simply use:
Redirect 301 /shopcontent.asp?type=FAQ%20and%20Terms /privacy-policy-cookie-restriction-mode
So I have worked out that this should work:
RewriteCond %{QUERY_STRING} ^type=FAQ%20and%20Terms$ [NC]
RewriteRule ^shopcontent\.asp$ /privacy-policy-cookie-restriction-mode/? [NC,R=301,L]
I have also tried removing the %20 for the spaces like this:
RewriteCond %{QUERY_STRING} ^type=FAQ\ and\ Terms$ [NC]
RewriteRule ^shopcontent\.asp$ /privacy-policy-cookie-restriction-mode/? [NC,R=301,L]
When I try and access the old URL it just goes to the 404 page. I am using standard .htaccess file that came with Magento (I can post if that helps);
I am using a VPS which mod rewrite is enabled. I have other Redirect 301's for non dynamic URLS.
Are there any logs that I can look at?
Appreciate any help or advice.
Thanks Rudi
ps. I found this post which got me to where i am now
RewriteCond %{QUERY_STRING} in mod_rewrite (dynamic to static URL) not working
You cant use this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} "^type=FAQ\%20and\%20Terms$" [NC]
RewriteRule ^shopcontent\.asp$ /privacy-policy-cookie-restriction-mode/? [NC,R=301,L]